Skip to content

Fix AutoFac Registrations so that IDaoFactory and IManagerFactory are SingleInstance #4

@MeoMix

Description

@MeoMix

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().SingleInstance();
//containerBuilder.RegisterType().As().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().As().InstancePerApiRequest();
containerBuilder.RegisterType().As().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

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions