对所有实例使用HybridHttpOrThreadLocalScoped

时间:2017-07-31 21:25:24

标签: c# asp.net-mvc inversion-of-control structuremap idisposable

我在ASP.NET MVC 5.x Web应用程序中使用结构图4.5.1 ,我执行扫描接口实现并为所有人添加The file will not be displayed in the editor because it is either binary, very large or uses an unsupported text encoding.其中包含以下代码:

HybridHttpOrThreadLocalScoped()
  1. 当我使用此代码时, 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()接口的所有接口添加了什么?如果答案是否定的,我怎么能这样做?
  2. 当我Sholud不使用IDisposable

1 个答案:

答案 0 :(得分:0)

  • HybridHttpOrThreadLocalScoped只是一个life-time说明符。因此,当您指定它时,它将用于所有请求和配置的实例,并且它在IDisposable或不是MATCH (tg:Tag)<-[:TAGGED]-(tp:Testplan) RETURN tg.tagName, count(DISTINCT tp.TP_MNEM) AS count ORDER by count DESC; 并不重要。它不是处理任何东西,而是一个终身指示器。
  • 如果您需要来自IoC容器的每个请求的新实例,请不要使用它。