Deepak
Deepak

Reputation: 303

Unity Container with Composition Root

I am new to DI and unity container. I am trying to use Unity with Composition Root. I have all my unity mappings/registrations in app.config file and just want to centralise all the resolve calls for my application.

The Application has many classes and very nested object graph created using constructor injection. So in a centralise location I want to create this object graph and then start make the call to do the actual work.

Please suggest a good way to implement composition root with unity.

Thanks!

Upvotes: 0

Views: 648

Answers (1)

tlp
tlp

Reputation: 129

I can suggest you a principle of composition root. Composition root is an application infrastructure component so only application should have it and it is the unique location where modules are composed together.

Moreover, It depends on your application that you are developing. For instance: - Console application . It's main method. - ASP.NET MVC application. It's global.asax

So no matter what is DI container. you can easily organize Composition root if you understand the principle behind that.

I'm not using Unity but I think, It's not much different with others

Hope it helps for you.

Upvotes: 2

Related Questions