aspnet / AspNetWebFormsDependencyInjection

Dependency injection support for ASP.NET Web Forms 4.x

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

How to use constructor injection with another container

gfox1984 opened this issue · comments

Hey,

I was able to successfully modify the code and use LightInject as a container. This allows me to access my services using the global object HttpRuntime.WebObjectActivator.

However, I would like to be able to inject dependencies in my pages via the constructor too.
I've attempted to simply add a parameter to the constructor to my About.aspx page:

public About(IDummyService dummy) { ... }

However, the LightInject container is unable to instanciate the page for me. When I debug the ContainerServiceProvider I implemented, LightInject simply doesn't know the type ASP.about_aspx service that's defined in a temporary assembly (eg: C:/Windows/Microsoft.NET/Framework64/v4.0.30319/Temporary ASP.NET Files/root/e15e9fc8/41270200/App_Web_cdps00j5.DLL).

What extra step is required to make an engine other than Unity support injection via constructor injection in the pages? Or can someone point me to the code that makes it possible with Unity?

Sorry for the delayed response. The truth is, I don't know the answer. The author of both this repo and the DI feature in ASP.Net has moved on long ago. And I am also not at all familiar with LightInject. I hope you were able to find a solution to this issue.

Warning
This project demonstrates building a dependency injection adapter for the Unity IoC container. It is a point of reference for other adapter authors. Please note that this implementation is for demonstration purposes only and is not being actively maintained.