I have an application with client, Library and Interface as a middle layer. The classes in the Library implement the Interface.I want to call the library without having to reference it. So I dont have to do this:
IInterface myClass = new Library.MyClass();
One way is to use Unity I guess. Is there any other way? Somehow the whole idea of the Interface fades away right now.
Thanks
There are a couple of ways you can do this. One, through the use of Dependency Inversion, as you show with Unity, and the other by writing class factories, and lastly, as you've mentioned, newing up the class instance, which is not really helpful at all :)
My own personal taste tends to Dependency Inversion, where Structuremap is my favourite IoC Container. Very easy to set up, and very easy to use, but most of the IoC Containers are very well documented.
The thing you typically end up with are something to the likes of:
IInterface myClass = myContainer.GetInstanceOf<IInterface>();