If you're willing to give up have dependencies injected into
your domain objects, things can be simplified immensely.
No need to use DI or IoC to create your entities.
Therefore, no need for repositories to reference either DI or
IoC.
If you're willing to have your repositories injected into your
services, then your service don't need to reference either DI or IoC.
Really, all you'd need to do is register your service and
repository types in the container and be done with it.
Hope that helps,
-- Udi Dahan
From: domaindrivendesign@yahoogroups.com
[mailto:domaindrivendesign@yahoogroups.com] On Behalf Of Justin
Daubenmire
Sent: Tuesday, July 14, 2009 11:00 PM
To: domaindrivendesign@yahoogroups.com
Subject: Re: [domaindrivendesign] IOC circular dependency question
Below is a simplistic example making use of 4 assemblies "IOC",
"Domain",
"Repositories" and "Services".
The "IOC" assembly contains two classes: 1) The DI container for
Ninject,
and 2) a class that serves as a Ninject Module where the binding rules are
defined.
The following article was the inspiration for this:
http://www.codethinked.com/post/2008/08/21/Creating-a-binding-factory-for-Ninject.aspx
The "Repositories" assembly will create Domain objects using Ninject
* The "Repositories" assembly needs a reference to "IOC" to
invoke the DI
container for the creation of Domain objects.
* The Domain object bindings need defined in the Ninject Module in the
"IOC"
assembly. As a result, the "IOC" assembly needs a reference to
"Domain"
The "Services" assembly will create Repository objects using Ninject
* The "Services" assembly needs a reference to "IOC" to
invoke the DI
container for the creation of Repository objects.
* The Repository object bindings need defined in the Ninject Module in the
"IOC" assembly. As a result, the "IOC" assembly need a
reference to
"Repositories"
At this point the circular dependency looks like this:
"Repositories" -> "IOC" -> "Repositories"
Hopefully that helps clear up the madness.
Any suggestions on how I could have done this better?
Thanks for any feedback!
Regards,
Justin
----- Original Message -----
From: "Michael Hart" <michael.hart.au@...>
To: <domaindrivendesign@yahoogroups.com>
Sent: Tuesday, July 14, 2009 9:48 AM
Subject: Re: [domaindrivendesign] IOC circular dependency question
> Hi Justin,
>
> So it's this step I don't understand:
>
>> At any time I need a concrete instance of something in the API, I
>> add a
>> reference of MyAppxxx.dll assembly to the IOC assembly.
>
> What is this "IOC" assembly? I don't quite get what its purpose
is.
> Can you give an example of a class from that assembly and how you use
> it?
>
> If you're creating a set of libraries, with no entry point, then how
> are you using your IoC container? You typically only need a container
> when you're instantiating your app and you want to define which
> specific implementations get injected.
>
> Cheers,
>
> Michael
>
>
> ------------------------------------
>
> Yahoo! Groups Links
>
>
>