diff --git a/src/FubuMVC.StructureMap/StructureMapContainerFacility.cs b/src/FubuMVC.StructureMap/StructureMapContainerFacility.cs index 1b6648661c..fd029b33d5 100755 --- a/src/FubuMVC.StructureMap/StructureMapContainerFacility.cs +++ b/src/FubuMVC.StructureMap/StructureMapContainerFacility.cs @@ -47,6 +47,20 @@ public StructureMapContainerFacility(IContainer container) _registry = new StructureMapFubuRegistry(); } + private bool _initializeSingletonsToWorkAroundSMBug = true; + + /// + /// Disable FubuMVC's protection for a known StructureMap nested container issue. + /// You will need to manually initialize any Singletons in Application_Start if they depend on instances scoped to a nested container. + /// See + /// + /// + public StructureMapContainerFacility DoNotInitializeSingletons() + { + _initializeSingletonsToWorkAroundSMBug = false; + return this; + } + public IActionBehavior BuildBehavior(ServiceArguments arguments, Guid behaviorId) { return Builder(_container, arguments, behaviorId); @@ -60,7 +74,10 @@ public IBehaviorFactory BuildFactory() x.AddRegistry(_registry); }); - initialize_Singletons_to_work_around_StructureMap_GitHub_Issue_3(); + if (_initializeSingletonsToWorkAroundSMBug) + { + initialize_Singletons_to_work_around_StructureMap_GitHub_Issue_3(); + } return this; }