Dependency Injection, ASMX Web Service

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.
12 anos atrás
Hi,

I am trying to use OrderService in an ASMX web service, however, I don't understand how pass the OrderService, using dependency injection, into the constructor:

public class WebService : System.Web.Services.WebService
    {

        #region "Constructor"
        public WebService()
        {
    
            InitializeComponent();

        }
}

Because I need a parameterless constructor, I am unable to do this:

public WebService(OrderService orderService)
{
_orderService = orderService;
}

Does anyone know a workaround?
12 anos atrás
joe_a84 wrote:
Hi,

I am trying to use OrderService in an ASMX web service, however, I don't understand how pass the OrderService, using dependency injection, into the constructor:

public class WebService : System.Web.Services.WebService
    {

        #region "Constructor"
        public WebService()
        {
    
            InitializeComponent();

        }
}

Because I need a parameterless constructor, I am unable to do this:

public WebService(OrderService orderService)
{
_orderService = orderService;
}

Does anyone know a workaround?



Currently it is not possible to inject dependencies into web services. You need to create a default no-argument constructor that initializes the dependencies. See the example below.


public WebService(){
_orderService = EngineContext.Current.Resolve<IOrderService>();
}
This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.