How to use Dependency Injection with ASP.NET

Posted by Schneider on Stack Overflow See other posts from Stack Overflow or by Schneider
Published on 2009-02-26T06:31:15Z Indexed on 2010/04/18 4:13 UTC
Read the original article Hit count: 377

I am trying to work out a way to use Dependency Injection with ASP.NET controls.

I have got lots of controls that create repositories directly, and use those to access and bind to data etc.

I am looking for a pattern where I can pass repositories to the controls externally (IoC), so my controls remain unaware of how repositories are constructed and where they come from etc.

I would prefer not to have a dependency on the IoC container from my controls, therefore I just want to be able to construct the controls with constructor or property injection.

(And just to complicate things, these controls are being constructed and placed on the page by a CMS at runtime!)

Any thoughts?

© Stack Overflow or respective owner

Related posts about inversion-of-control

Related posts about ASP.NET