tags:

views:

46

answers:

2

I am not sure if there is any interface already exist in .Net like this:

public interface IController {
      T GetInstance<T>(string name) where T: class;
}

Basically, this interface contains a method to get instance of T by name/key. IControler is an arbitrator name I use here. It may be something like IFactory, ICreator, or something I don't know. The method name may not exactly like this(GetInstance). I think this may be a generic method which can be used to get/query an instance from a container, parent or controller.

If there is one, I would not need to create one(just adding a reference); otherwise, I'll define one.

+2  A: 

this sounds exactly like an IoC container. You might want to look at the common service locator

Ruben
This is very nice link. The interface of IServiceLocator provides more generic interfaces for my case. I like their methods as well, better than my. Thanks!
David.Chu.ca
+1  A: 

This problem has generally been solved by container-managed repositories, which are at the heart of Dependency Injection frameworks like Unity, StructureMap and NInject.

codekaizen
This is exactly my case. The parent class contains a container which needs to be initialized and then I need to the container to get instances by this interface or outside and nested classes.
David.Chu.ca
@David.Chu.ca: It sounds like you need dependency injection to do your type resolution, then!
codekaizen