开发者

HttpHandler, Unity, Dependency Injection (DI), web.config is it even possible?

 public class MyHttpHandler : IHttpHandler
 {
      public MyHttpHandler() { ... }

      public IUnityContainer Container { get; set; }
 }

I开发者_StackOverflow中文版s there a way to somehow get Container magically be set to a container I setup in global.asax?

Right now I can't find a way of doing it other than using AppDomain.CurrentDomain.GetData("container") as IUnityContainer.

Please let me know if there is a cleaner way of doing this.


First hit on google for asp.net mvc2 unity

http://weblogs.asp.net/shijuvarghese/archive/2010/05/07/dependency-injection-in-asp-net-mvc-nerddinner-app-using-unity-2-0.aspx

There are plenty of articles about MVC and Unity. You basically need to create a custom controller factory (in mvc2). MVC3 got a different solution.

Update

Use the BuildUp method in global.asax.

Sry. that was for existing objects. Why not just Register it and directly after Resolve it?


Singleton pattern may help you)


I would use service location instead.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜