WAS. Non-HTTP Activation - Launch Application Launch

I am trying to integrate a netTcpBinding based application hosted inside a WAS with an IoC container (autofac / spring). Unfortunately, when it starts with WAS and because it is not an Http based application, no events are fired in the global application class.

I need to catch the launch of the application so that I can configure the IoC container. Is there a way to do this when hosted in WAS?

I saw terrible things related to using static classes inside App_Code folders, but I would like something somewhat more verifiable and not quite dirty.

+3
source share
1 answer

IInstanceProvider (. http://msdn.microsoft.com/en-us/library/system.servicemodel.dispatcher.iinstanceprovider.aspx) WCF .

, . :

public class DependencyInjectionServiceBehaviorAttribute : Attribute, IServiceBehavior
{
    public void ApplyDispatchBehavior(ServiceDescription serviceDescription, ServiceHostBase serviceHostBase)
    {
        foreach (var cdb in serviceHostBase.ChannelDispatchers)
        {
            var cd = cdb as ChannelDispatcher;
            if (cd != null)
            {
                foreach (EndpointDispatcher ed in cd.Endpoints)
                {
                    ed.DispatchRuntime.InstanceProvider = new MyServiceFactory(serviceDescription.ServiceType);
                }
            }
        }
    }

    public void AddBindingParameters(ServiceDescription serviceDescription, ServiceHostBase serviceHostBase,  
            Collection<ServiceEndpoint> endpoints, BindingParameterCollection bindingParameters) {}
    public void Validate(ServiceDescription serviceDescription, ServiceHostBase serviceHostBase) {}
}
0

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


All Articles