Fix AutoFac Registrations so that IDaoFactory and IManagerFactory are SingleInstance
I've been trying to figure out how to properly use AutoFac and I think I'm almost there, but I've hit one final snag that I'm struggling with.
Inside of AutoFacRegistrations.cs, I've got:
//containerBuilder.Register(x => new NHibernateDaoFactory()).As<IDaoFactory>().SingleInstance(); //containerBuilder.RegisterType<StreamusManagerFactory>().As<IManagerFactory>().SingleInstance();
// TODO: Still not really sure why I need InstancePerApiRequest here. Figure it out! Maybe if I removed the need to pass params into ManagerFactory it'll be OK containerBuilder.RegisterType<NHibernateDaoFactory>().As<IDaoFactory>().InstancePerApiRequest(); containerBuilder.RegisterType<StreamusManagerFactory>().As<IManagerFactory>().InstancePerApiRequest();
It should be possible (and is best practice) to only instantiate a single instance of a Factory. However, my test cases fail when I try to use SingleInstance.
For reference:
http://codereview.stackexchange.com/questions/44170/should-a-factory-ever-be-generated-per-request
http://stackoverflow.com/questions/22331095/transitioning-to-autofacwebapidependencyresolver-from-mvcs-dependencyresolver/22359352#22359352