WCF Integration Facility and Self-Hosted Services

I host several services on my own, where I do this to register the service:

host = new ServiceHost(typeof(MyService));
host.Open();

Behind the scenes, wcf starts my service through the default constructor.

Is it possible to use the WCF Integration Facility for Castle Windsor to force WCF to call Windsor to create a service when I'm hosting?

The example shows that IIS, where the first line of the MyService.svc file looks like this:

<%@ServiceHost language=c# Debug="true" 
     Service="Microsoft.ServiceModel.Samples.CalculatorService" 
     Factory=WindsorServiceHostFactory%>

where presumably a factory is used by wcf to instantiate the service.

+3
source share
2 answers

Castle 3.0 :

// setup IoC, including registering the WcfFacility from Castle.WcfIntegrationFacility
container.AddFacility<WcfFacility>();
// and all other registrations you need

, , app.config, :

// T is an interface with a backing service implementation registered in your IoC
public static ServiceHostBase StartHostService<T>(string serviceUrl)
{
    var assemblyQualifiedName = typeof(T).AssemblyQualifiedName;
    var serviceHost = new DefaultServiceHostFactory()
        .CreateServiceHost(assemblyQualifiedName, new[] { new Uri(serviceUrl) });
    serviceHost.Open();

    return serviceHost;
}
0

Source: https://habr.com/ru/post/1738401/


All Articles