Tag: structuremap3

在结构图3中,HybridHttpOrThreadLocalScoped的等价物是什么?

使用structuremap 2.6.4.1,我的容器配置如下: existingContainer.Configure(expression => { expression.For() .HybridHttpOrThreadLocalScoped() .Use(container => { var store = container.GetInstance(); return store.OpenSession(); }); } 结构图3中不存在HybridHttpOrThreadLocalScoped ,所以我的问题是,structuremap 3中的等效配置是什么?

被动属性和嵌套容器

最终解决方案 在@ NightOwl888的答案的帮助下,这是我最后的方法,对于任何最终到此的人: 1)添加了全局filter提供程序: public class GlobalFilterProvider : IFilterProvider { public IEnumerable GetFilters(ControllerContext controllerContext, ActionDescriptor actionDescriptor) { var nestedContainer = StructuremapMvc.StructureMapDependencyScope.CurrentNestedContainer; foreach (var filter in nestedContainer.GetAllInstances()) { yield return new Filter(filter, FilterScope.Global, order: null); } foreach (var filter in nestedContainer.GetAllInstances()) { yield return new Filter(filter, FilterScope.Global, order: null); } foreach (var filter in nestedContainer.GetAllInstances()) { […]

从StructureMap获取的HttpContext上的Null User

好吧,我之前的问题/设置有太多的变量,所以我把它剥离到它的裸骨组件。 给出下面的代码使用StructureMap3 … //IoC setup For().UseSpecial(x => x.ConstructedBy(y => HttpContext.Current != null ? new HttpContextWrapper(HttpContext.Current) : null )); For().Use(); //Classes used public class CurrentUser : ICurrentUser { public CurrentUser(HttpContextBase httpContext) { if (httpContext == null) return; if (httpContext.User == null) return; var user = httpContext.User; if (!user.Identity.IsAuthenticated) return; UserId = httpContext.User.GetIdentityId().GetValueOrDefault(); UserName = httpContext.User.Identity.Name; } […]