Search code examples
.netinversion-of-controlasmx

Use IoC with old web service project


I got an old (2008) three layered back office system:

  • Web service layer; asmx type web services. Probably made from the "ASP.NET Web Service Application"- template
  • Business layer; I don't want to touch this.
  • Data layer; A mess. All sorts of data access.

My goal is to clean up this, write some unit tests etc.

For a start; Is it possible to add an IoC-container. Where should it initialized? The project is currently running on .NET Framework 3.5.

Ivar


Solution

  • Have found good article for you

    http://ruijarimba.wordpress.com/2011/12/27/asp-net-web-services-dependency-injection-using-unity/

    In short words:

    1. Set up DI/IoC container in global.asax.cs and have their Container property to access your DI/IoC container

    2. Resolve your dependencies or build container in constructor of your service, or create a base class as the example shows

    3. Optionally when you need you can resolve your dependency from container a-la "Service locator"