Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Castle Windsor Typed Factory Facility equivalents

do any other .NET IoC containers provide equivalent functionality to the typed factory facility in Castle Windsor?

e.g. if I am using an abstract factory pattern in a WPF application:

public class MyViewModel
{
   private IAnotherViewModelFactory factory;

   public void ShowAnotherViewModel()
   {
      viewController.ShowView(factory.GetAnotherViewModel());
   }
}

I don't want to have to create a manual implementation of IAnotherViewModelFactory for every type of ViewModel I wish to show, I want the container to take care of this for me.

like image 464
devdigital Avatar asked Nov 06 '10 14:11

devdigital


1 Answers

AutoFac has a feature called Delegate Factories, but as far as I can tell, it works only with delegates, and not interfaces.

I haven't encountered anything similar to Castle's Typed Factory Facility in neither StructureMap nor Unity, but that doesn't necessarily mean that they're not there...


The only way I can imagine that something like this could be implemented for interfaces is via a dynamic proxy. Since Castle Windsor has a Dynamic Proxy, but few other containers have anything similar, this might go a long way to explain why this feature isn't ubiquitous.

Unity also offers interception capabilities, so it must have some sort of dynamic proxy implementation, but I'm pretty sure it doesn't have anything equivalent to Typed Factories. Compared to other containers, Unity is rather basic.

like image 123
Mark Seemann Avatar answered Sep 22 '22 12:09

Mark Seemann