相关疑难解决方法(0)

HttpSelfHostServer和HttpContext.Current

我正在开发一个自托管的ASP.NET web api-application.一切正常,但现在我正在努力HttpContext:

我需要从客户端保存会话信息.但HttpContext.Current总是空的.所以很明显我HttpSelfHostServer不使用静态HttpContext-Class.

我不明白的是:为什么......?而且我无法想办法既不告诉也HtttpSelfHostServer不能HttpSelfHostConfiguration合作HttpContext.

这是我正在做的事情:

  1. 创建一个 HttpSelfHostConfiguration

    • 1.1添加Service-Resolvers&Routes
    • 1.2添加自定义 UserNamePassword-Validator
  2. 使用config创建新的HttpSelfHostServer实例

    • 2.1 server.OpenAsync().Wait()

任何帮助我如何告诉我的服务器工作HttpContext.Current非常感谢!干杯!

c# self-hosting httpcontext asp.net-web-api

18
推荐指数
2
解决办法
1万
查看次数

Unity Application Block,如何将参数传递给Injection Factory?

这就是我现在所拥有的

  Container.RegisterType<IUserManager, UserManagerMock>();
  Container.RegisterType<IUser, UserMock>(
                new InjectionFactory(
                    (c) => c.Resolve<IUserManager>().GetUser("John")));
Run Code Online (Sandbox Code Playgroud)

得到它

Container.Resolve<IProfile>();
Run Code Online (Sandbox Code Playgroud)

我想将一个名称作为参数传递给Factory,以便我能够用名称解析用户对象; 像这样的东西:

 Container.Resolve<IProfile>("Jonh");
Run Code Online (Sandbox Code Playgroud)

如何更改此案例的类型注册?

.net c# ioc-container unity2.0

8
推荐指数
2
解决办法
9542
查看次数