I use structure map 4.5.1 in my ASP.NET MVC 5.x Web Application and I do Scan Interface implementations and add HybridHttpOrThreadLocalScoped()
for all of them with following codes:
public static class SmObjectFactory
{
private static readonly Lazy<StructureMap.Container> _containerBuilder =
new Lazy<StructureMap.Container>(DefaultContainer, LazyThreadSafetyMode.ExecutionAndPublication);
public static IContainer Container => _containerBuilder.Value;
private static StructureMap.Container DefaultContainer()
{
return new StructureMap.Container(config =>
{
config.Scan(scanner =>
{
scanner.AssemblyContainingType(typeof(IPostService));
scanner.WithDefaultConventions();
scanner.SingleImplementationsOfInterface()
.OnAddedPluginTypes(expression =>
expression.HybridHttpOrThreadLocalScoped());
});
});
}
}
HybridHttpOrThreadLocalScoped()
it do added for All Interfacs that inherent IDisposable
Interface ? if answer is no how can I do this ?HybridHttpOrThreadLocalScoped()
?HybridHttpOrThreadLocalScoped
is just a life-time
specifier. so when you specify it, it will be used for all of the requested and configured instances and here it's not important that it's IDisposable
or not. It's not about disposing anything, it's a life-time specifier.