Click here to Skip to main content
15,881,424 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
hi all,
i have a C# application (this is not or silverlight ) which has a main class and several other classes. I wanted to introduce dependency inversion using MS Unity Application block 2.0
the structure of the app is such that in the main class, objects of 2 other classes were created and functions of these classes were used.These two classes in turn used the objects and functions of the rest of the classes.
So to do this, i added a unity container and registered the types for the 2 classes:
something like this
_unityContainer = new UnityContainer();
_unityContainer.RegisterType<Class1>(new InjectionConstructor(var1,var2));
_unityContainer.RegisterType<Class2>(new InjectionConstructor(var3));

So in order to implement dependency inversion properly,is it necessary to register the types of the rest of the classes also with this container ?
(As this main class is not using any object/functions from rest of the classes directly.
Updated 2-Apr-12 11:35am
Dean Oliver 27-Feb-12 4:45am    
chandanadhikari 29-Feb-12 2:21am    
Hi Dean Oliver,
thanks for your response...can you please shed some light on why exactly is this necessary...or maybe point me to someplace where i can find more info

1 solution

It's all got to do with object lifetime. and unit testing. Here's an article that can shed some light on the subject for you.[^]
Share this answer
chandanadhikari 2-Apr-12 23:52pm    
thanks for the link

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900