Click here to Skip to main content
15,847,583 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hi,
please let me know the concept of Resolving class using interface using UNITY ...
with a simple example....
Posted

1 solution

interface IThing { int DoStuff(); }
class Thing: IThing { public int DoStuff(){ return 42; } }

void UnityTest(){
 // Here's how you register
 unityContainer.RegisterType<IThing, Thing>();

 // ... and here's how you resolve
 IThing thing = unityContainer.Resolve<IThing>();
 
 int answer = thing.DoStuff(); // will be 42
}


I'm sure Google could have found you that. Please put a bit of effort in before asking on here.
 
Share this answer
 
v2
Comments
siva455 12-Jul-11 10:12am    
thanks for ur code snippet...actually i want to know what is the purpose of using unity container...in simple words...what is the advantage of this concept...as u said i can get this in google...but the real concept is where i can learn from seniors like you...pls correct me if im wrong...
Just want to know the advantage of using this design pattern(Ioc)...and how does it makes difference from normal approach...
BobJanova 12-Jul-11 10:33am    
What it gives you is that you can change registrations at runtime, so you can get an IThing which is appropriate to the current context. It is commonly used for modular applications to get information providers for display regions, menus, statusbars etc. I am not an expert, though (just happen to be using Unity on a project right now).
siva455 12-Jul-11 10:38am    
thanks for ur reply...sorry to say this but i didn"t get what you are trying to explain....may be i need to google more to understand the basic idea of using unity...

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