开发者

Wanna use StructureMap to store HttpContext/User based explicit instances

I'm having difficulty figuring out how to store an explicitly user generated instance in StructureMap, cached by HttpContext. When I try the code underneath, I even get the first cached instance, which leads to failures when using it for storing user credentials in Asp.Net AuthenticateRequest method.

ForRequestedType<TInterface>()
                            .CacheBy(InstanceScope.HttpContext)
                                .TheDefault.
      开发者_如何学C                              Is.
                                        Object(instance));

The problem is I can't create a new instance on requesting StructureMap, because I need more other factories for getting rights etc. for the current user.

Any ideas?


Here is my registry config that I use for an ASP.Net MVC app

For<ICurrentUser>().HybridHttpOrThreadLocalScoped().Use<CurrentUser>();

I configure the CurrentUser instance after checking the authentication status of the user. This happens in an authorization action filter. Each subsequent type needing ICurrentUser receives the properly setup instance as it is cached scoped to the web request.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜