If you do have multiple implementers of the ICustomer interface (I will
agree with Chad that having 1:1 interface:entity is usually an antipattern),
then there is nothing stopping you from mapping to ICustomer. In the case
where you are retrieving an existing customer or navigating a relationship,
NHibernate will instantiate the correct type of instance for you, so there
is no need for your IoC container to be involved. In the case of creating a
new customer instance, use the factory pattern as I mentioned in my previous
email.

Chad and James both nailed it, in terms of why you should not use an IoC
container to manage entities. Services by their very nature are easily
managed with an IoC container. Usually they have a very simple lifecycle,
and it can often make sense to have different implementations of a
particular service, for example you could have a repository implementation
that uses NHibernate to talk to the database, and another implementation
that stores objects in memory, for the purposes of testing. With entities it
is not so straightforward - their lifecycles are usually much more
complicated, and furthermore there is less justification for using IoC; it
is unlikely that you will want to 'swap in' different implementations of
Customer.

Hope this helps,

Paul Batum


On Sun, Oct 5, 2008 at 7:14 PM, <[EMAIL PROTECTED]> wrote:

>
> I don't fully understand why you should not use an IoC Container for
> entities I will accept that and research it further so that I do
> understand. So if you are not using an IoC Container for your entities
> then you do not need to have a type of ICustomer in your parent
> object, you would just map to Customer as an entity. So how do you
> keep louse coupling between objects when you don't want to use an IoC
> container or map to interfaces, etc...
>
> On Oct 5, 6:16 am, "Paul Batum" <[EMAIL PROTECTED]> wrote:
> > While I will disagree with Chad and say it is fine for entities to
> implement
> > interfaces, I will absolutely agree that is NOT a good idea for your
> > entities to be managed by an IoC container.
> >
> > If for whatever reason you need to abstract the construction of a
> particular
> > type of customer and want the calling code to simply receive and
> ICustomer,
> > I suggest you use the factory pattern to manage the creation of that
> > Customer object, not by using an IoC container. That is, make a
> > CustomerFactory and use that.
> >
> > For future reference, if you have a general question about using
> NHibernate
> > that is not specifically about using the FluentNHibernate API then I
> suggest
> > you post the question to the nhibernate
> > users<http://groups.google.com/group/nhusers?hl=en>mailing list.
> >
> > Paul Batum
> >
> >
> >
> > On Sun, Oct 5, 2008 at 2:53 AM, Chad Myers <[EMAIL PROTECTED]> wrote:
> >
> > > It is generally not a good idea for entities to implement an interface
> > > and/or be serviced through an IoC container.
> >
> > > I think that this is why you're struggling with this. Is it possible
> for
> > > you to not put  these things in a container?
> > > -c
> >
> > > -----Original Message-----
> > > From: fluent-nhibernate@googlegroups.com
> > > [mailto:[EMAIL PROTECTED] On Behalf Of
> > > [EMAIL PROTECTED]
> > > Sent: Saturday, October 04, 2008 7:14 PM
> > > To: Fluent NHibernate
> > > Subject: [fluent-nhib] Mapping interfaces
> >
> > > I have an object that has a child object ICustomer. When I instantiate
> > > ICustomer using StructureMap it is a Customer which implements
> > > ICustomer. Now everything worked fine before I had the child as
> > > ICustomer.
> >
> > > If I map ICustomer then i get an error about not knowing about
> > > Customer and vis-versa if I map Customer. If I map them both I get an
> > > error about there being an instance of ICustomer still in "memory"
> >
> > > So what is the correct way to handle this situation?- Hide quoted text
> -
> >
> > - Show quoted text -
> >
>

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

Reply via email to