Take the 2-minute tour ×

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.

share|improve this question
If it existed, it would more likely be a generic interface, rather than a non-generic one with a generic method. –  Anon. Jan 25 '10 at 21:26
add comment

2 Answers

up vote 2 down vote accepted

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

share|improve this answer
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 Jan 25 '10 at 21:44
add comment

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

share|improve this answer
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 Jan 25 '10 at 21:40
@David.Chu.ca: It sounds like you need dependency injection to do your type resolution, then! –  codekaizen Jan 25 '10 at 21:45
add comment

Your Answer


