0

I work with legacy code and try to implement DI pattern in asp.net web service (asmx files) using ninject, but i don`t know where and how to initialize service-locator, that will track dependencies.

Any examples and advices will be usefull, thanks

Rui Jarimba
  • 11,166
  • 11
  • 56
  • 86
Arthur
  • 35
  • 7
  • duplicated? http://stackoverflow.com/questions/12378026/ninject-w-asmx-web-service-in-a-mvc3-ninject-3-environment – MichaC Sep 26 '13 at 11:11
  • I worte an article about web services DI using Unity but maybe you can take some ideas and make it work using NInject: http://ruijarimba.wordpress.com/2011/12/27/asp-net-web-services-dependency-injection-using-unity/ – Rui Jarimba Sep 26 '13 at 11:20
  • @rui-jarimba your article seems to be like exactly what I try to do. Maybe, I can use Unity, instead of Ninject. – Arthur Sep 26 '13 at 11:30

2 Answers2

0

There's a ninject module for asp.net webforms. Instructions on setting it up are here. After that, all you have to do is specify how to resolve you're dependencies and then add an [Inject]able property for each dependency you want injected in you're asmx.cs file

Community
  • 1
  • 1
Nicolas Straub
  • 3,381
  • 6
  • 21
  • 42
0

This is an old question, but since I was taken here first by a search engine I thought I would add a pointer to another question with the answer:

Answer

The gyst of it is that your web service needs to inherit from Ninject.Web.WebServiceBase instead of System.Web.Services.WebService

Then you can inject into it using the [Inject] annotation.

Community
  • 1
  • 1
Ryan McArthur
  • 508
  • 5
  • 12