I wouldn't use container.Resolve ... but similar idea ... It prevents
your domain objet from needing the dependency outside of the scope of
the operation (construction). The need is unfortunately more of a
technical one due to how the language works but by introducing the
separation it can be avoided.

Beyond all of that I would say that this is a great place where cqs
coud help ... are the varying hashes even really a domain concern or
just a reporting concern?



On Thu, Mar 26, 2009 at 12:43 PM, Peter Morris <[email protected]> wrote:
>
>>> Did you mean persistent or transient?  I need a transient dependency to a
>>> service.
>
>
>>Not surprisingly I am using the definition of transient itself not
>>refering to a transient vs persistent object. In other words for 95+%
>>of cases the object does not need to *remember* which service to use,
>>it just needs to be given one for the duration of an operation.
>
> Oh right.  It was somewhat confusing because we are discussing ORM which has
> transient and persistent members, and IoC which (in Unity at least) as
> controller lifetime services and transient services.  So I had no idea what
> you were talking about :-)
>
>
>> These
>> can be handled through double dispatch ...
>
> I could have
>
>    public void SetName(string Name, IWordHashService wordHashService)
>
> but then I would have to resolve the service myself, and I really like all
> of that to be done for me.  I do have places where I have services as
> parameters on methods and I don't like it, it just seems wrong to me,
> especially when there are a few services.  Having these services
> "automagically" available is more appealing.
>
>>Your code example is slightly off ... the builder should not be
>>handing the service to the object but should be using the service to
>>get the data to pass to the object.
>
> Yes, that makes sense.  So you mean something like this?
>
> public class Song
> {
>    public class SongBuilder
>    {
>        IWordHashService WordHashService;
>        public SongBuilder(IWordHashService wordHashService)
>        {
>            WordHashService = wordHashService;
>        }
>
>        public Song CreateSong(string name)
>        {
>            return new Song(name, WordHashService.CreateWordHashes(name));
>        }
>    }
>
>
>    IWordHashService WordHashService;
>    private Song(string name, int[] wordHashes)
>    {
>        //Validate Name
>        Name = name;
>        //Store the word hashes
>    }
>
>    private string name;
>    public string Name
>    {
>        get { return name; }
>    }
> }
>
> And use it like so....
>
>    Song = container.Resolve<Song.SongBuilder>().CreateSong("Meh");
>
> Is that what you mean?
>
>
> Pete
> ====
> http://mrpmorris.blogspot.com
>
>
> >
>



-- 
It is the mark of an educated mind to be able to entertain a thought
without accepting it.

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"nhusers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/nhusers?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to