Search the web
Sign In
New User? Sign Up
domaindrivendesign · Domain-Driven Design
? Already a member? Sign in to Yahoo!

Yahoo! Groups Tips

Did you know...
Hear how Yahoo! Groups has changed the lives of others. Take me there.

Best of Y! Groups

   Check them out and nominate your group.
Having problems with message search? Fill out this form to ensure your group is one of the first to be migrated to the new message search system.

Messages

  Messages Help
Advanced
IOC circular dependency question   Message List  
Reply | Forward Message #13833 of 16018 |
RE: [domaindrivendesign] IOC circular dependency question

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
>
>
>



Tue Jul 14, 2009 9:28 pm

udidahan7
Offline Offline
Send Email Send Email

Attachment
image001.jpg
Type:
image/jpeg
Attachment
image002.jpg
Type:
image/jpeg
Forward
Message #13833 of 16018 |
Expand Messages Author Sort by Date

Hey all, Quick question. When using an IOC in c#.net assemblies - such as Ninject - how do you prevent circular dependencies? I have this: MyApp.IOC ...
Justin Daubenmire
JDaubenm
Offline Send Email
Jul 13, 2009
10:52 pm

... Have a look at Common Service Locator - http://www.codeplex.com/CommonServiceLocator -- Richard Dingwall http://richarddingwall.name...
Richard Dingwall
rdingwall@...
Send Email
Jul 13, 2009
10:55 pm

Er, I don't think CommonServiceLocator is what you want. CommonServiceLocator is intended for libraries who want to support multiple IoC containers. That's...
Michael Hart
michaelhartau
Offline Send Email
Jul 14, 2009
2:33 am

... Put the interfaces for your repositories/services in your domain assembly: they *are* part of the domain. The repository/service implementations then can...
Dan Haywood
danh024680
Offline Send Email
Jul 13, 2009
11:02 pm

... From: "Richard Dingwall" <rdingwall@...> Have a look at Common Service Locator - http://www.codeplex.com/CommonServiceLocator Thanks! Do you know if...
Justin Daubenmire
JDaubenm
Offline Send Email
Jul 13, 2009
11:25 pm

... Here: http://code.google.com/p/ninject/source/browse/#svn/experiments/ninject2/src/CommonServiceLocator.NinjectAdapter -- Richard Dingwall ...
Richard Dingwall
rdingwall@...
Send Email
Jul 13, 2009
11:42 pm

... From: "Richard Dingwall" <rdingwall@...> ... Thanks Richard! Which .NET IOC do you actually use? Regards, Justin...
Justin Daubenmire
JDaubenm
Offline Send Email
Jul 14, 2009
12:21 am

... We are using Unity at the moment. Maybe not the best but it's doing the job so far :) -- Richard Dingwall http://richarddingwall.name...
Richard Dingwall
rdingwall@...
Send Email
Jul 14, 2009
1:58 am

... From: "Richard Dingwall" <rdingwall@...> We are using Unity at the moment. Maybe not the best but it's doing the job so far :) Cool, what other ones...
Justin Daubenmire
JDaubenm
Offline Send Email
Jul 14, 2009
2:23 am

Hi Michael, The MyApp.Domain name and MyApp.IOC are just made up silly names. I'd never name a real project something like that. :) If understanding you...
Justin Daubenmire
JDaubenm
Offline Send Email
Jul 14, 2009
12:41 pm

Hey Justin, You might need to give us more detail as to what you were trying to do with the projects - I realise that the "MyApp" is just an artificial name of...
Michael Hart
michaelhartau
Offline Send Email
Jul 14, 2009
1:15 pm

Sure, no problem. I am developing an API so I do not have a UI layer. There are a total of 20 assemblies in the API project. At any time I need a concrete...
Justin Daubenmire
JDaubenm
Offline Send Email
Jul 14, 2009
1:37 pm

Hi Justin, ... 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...
Michael Hart
michaelhartau
Offline Send Email
Jul 14, 2009
1:49 pm

Below is a simplistic example making use of 4 assemblies "IOC", "Domain", "Repositories" and "Services". The "IOC" assembly contains two classes: 1) The DI...
Justin Daubenmire
JDaubenm
Offline Send Email
Jul 14, 2009
7:59 pm

Are you building an API layer that is meant to be completely self-contained and reused in any context? If so, there are some additional questions that need to...
Matt Burton
matt.burton
Offline Send Email
Jul 14, 2009
8:27 pm

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...
Udi Dahan
udidahan7
Offline Send Email
Jul 14, 2009
9:29 pm

Hi Justin, Matt and Udi have given good suggestions on this already, but I'll just add a few things: 1. The page you refer to uses a static singleton to access...
Michael Hart
michaelhartau
Offline Send Email
Jul 15, 2009
12:42 am

... From: "Matt Burton" <matt.burton@...> - Are you looking to Ninject to stitch together your own internal dependencies or... ... Yes, that is why we...
Justin Daubenmire
JDaubenm
Offline Send Email
Jul 14, 2009
11:54 pm

Alright - I would refer you to Udi's response, then - you just need to reel it in a bit. Keep it clean and simple - have your dependencies as constructor...
Matt Burton
matt.burton
Offline Send Email
Jul 15, 2009
6:29 am

Thanks guys for all the feedback and advice... much appreciated! Regards, Justin ... From: "Matt Burton" <matt.burton@...> To:...
Justin Daubenmire
JDaubenm
Offline Send Email
Jul 15, 2009
8:52 am

Hey guys, One more quick question on constructor injection. I have this constructor in my application layer: public fu(IView view) { this._view = view; // how...
Justin Daubenmire
JDaubenm
Offline Send Email
Jul 15, 2009
9:41 am

Hey guys, I came across this quick blog post about this scenario: http://kohari.org/2008/06/18/playing-nice-with-service-locators/ It looks like I have two...
Justin Daubenmire
JDaubenm
Offline Send Email
Jul 15, 2009
9:50 am

Hi Justin, Definitely go for #1 until you find a situation where it's not manageable. Also, maybe any more IoC questions are better to ask on the Ninject list?...
Michael Hart
michaelhartau
Offline Send Email
Jul 15, 2009
10:01 am

So if following you, you are suggesting to use a service locater and an IOC tool. Is that correct? btw I agree about taking Ninject questions / IOC to the...
Justin Daubenmire
JDaubenm
Offline Send Email
Jul 15, 2009
10:10 am

Hi Mike, I understand what you meant by going with option 1. Sorry, programming early mornings does have its limitations! =) Regards, Justin ... From: "Michael...
Justin Daubenmire
JDaubenm
Offline Send Email
Jul 15, 2009
10:38 am
Advanced

Copyright © 2009 Yahoo! Inc. All rights reserved.
Privacy Policy - Terms of Service - Guidelines - Help