1

Does StructureMap have a feature similar to CastleWindsor's TypedFactoryFacility, where it can generate an abstract factory on the fly?

Windsor example here: http://blog.ploeh.dk/2012/03/15/ImplementinganAbstractFactory/

JMarsch
  • 21,484
  • 15
  • 77
  • 125
  • I don't think there is: https://groups.google.com/forum/#!topic/structuremap-users/0QA86QOEA_U. In general however, I would say such feature is redundant, since creating such factory manually takes a few lines of code, and when applying DI correctly, there is not that much need for factories at all. So you'll probably just be creating a few factory interfaces. – Steven Jun 13 '14 at 07:11
  • Hi Steven: I ended up finding the feature. It does sound funny to mix a factory and DI, but sometimes it happens! If you are interested in why you would do this, I would suggest my link above. It is unusual, but sometimes handy. For example, maybe you want both injection and lazy-init, or maybe the object that your container resolves creates a variable number of threads, each needing a resource such as a dbConnection. In my case, I had a WebAPI controller that would only sometimes need an expensive pluggable resource. I use DI to inject the factory so it is pay-for-play. – JMarsch Jun 13 '14 at 22:59
  • @Steven ok, just saw your bio. Given that you have written a DI injector, I guess you already know all that stuff I just said. Cheers :) – JMarsch Jun 13 '14 at 23:10
  • 1
    I'm sorry. My first comment was a bit misleading. I didn't mean to say that you never need factories when doing DI. What I meant was that you need them considerably less. But factories are still needed sometimes and I do use them in my applications too. – Steven Jun 14 '14 at 07:52

1 Answers1

0

I think I found my answer. I will post it in case anyone else is looking:

http://timkellogg.me/blog/2012/06/12/AutoFactories-In-StructureMap

JMarsch
  • 21,484
  • 15
  • 77
  • 125