Navigation Menu

Skip to content

Commit

Permalink
Allow disabling StructureMap nested container issue workaround.
Browse files Browse the repository at this point in the history
By default, a StructureMapContainerFacilitity will now automatically
initialize all singletons when building the behavior factory.
You can opt-out of this behavior by calling DoNotInitializeSingletons()
on the facility before calling BuildFactory()
  • Loading branch information
joshuaflanagan committed Jun 3, 2010
1 parent cfd7daa commit 385e83d
Showing 1 changed file with 18 additions and 1 deletion.
19 changes: 18 additions & 1 deletion src/FubuMVC.StructureMap/StructureMapContainerFacility.cs
Expand Up @@ -47,6 +47,20 @@ public StructureMapContainerFacility(IContainer container)
_registry = new StructureMapFubuRegistry();
}

private bool _initializeSingletonsToWorkAroundSMBug = true;

/// <summary>
/// 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 <see cref="http://github.com/structuremap/structuremap/issues#issue/3"/>
/// </summary>
/// <returns></returns>
public StructureMapContainerFacility DoNotInitializeSingletons()
{
_initializeSingletonsToWorkAroundSMBug = false;
return this;
}

public IActionBehavior BuildBehavior(ServiceArguments arguments, Guid behaviorId)
{
return Builder(_container, arguments, behaviorId);
Expand All @@ -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;
}
Expand Down

0 comments on commit 385e83d

Please sign in to comment.