AUTOFAC injection of common services and WCF services

Source: Internet
Author: User

Using AUTOFAC;
Using Autofac.builder;
Using Autofac.core;

Implementing AUTOFAC Extensions

public static AUTOFACREGISTERWCF

{

public static Iregistrationbuilder<tservicecontract, Simpleactivatordata, singleregistrationstyle> Registerwcfservicecontract<tservicecontract> (This Containerbuilder builder, string endpointconfigurationname = null)
{
if (builder = = null)
{
throw new ArgumentNullException ("Builder");
}
Return autofac.integration.wcf.registrationextensions.usewcfsaferelease<tservicecontract, SimpleActivatorData , Singleregistrationstyle> (builder. Register (icomponentcontext _) = new Channelfactory<tservicecontract> (endpointconfigurationname?? typeof ( Tservicecontract). FullName). CreateChannel ()). As<tservicecontract> ());
}

}

Defining WCF configuration information in Webconfig

<system.serviceModel>
<servicehostingenvironment aspnetcompatibilityenabled= "true" multiplesitebindingsenabled= "true"/>

<bindings>

<customBinding>
<binding name= "SERVICESOAP12" closetimeout= "00:00:10" opentimeout= "00:00:05" receivetimeout= "00:00:05" sendtimeout= "00:00:05" >
<textmessageencoding messageversion= "Soap12"/>
</binding>

</customBinding>
</bindings>

<client>

<!--SMS Gateway Service--
<endpoint address= "http://127.0.0.1:19922/SMS/SendMessage?wsdl" binding= "custombinding" bindingconfiguration= " ServiceSoap12 "contract=" G2. Sendmessage.ismsservice "Name=" G2. Sendmessage.ismsservice "/>

</clien>

</system.serviceModel>

The third step is to register the WCF service when the project starts

WCF Service Injection

public void REGISTERWCF (Autofac.containerbuilder builder)
{

SendMessage Service Injection
Builder. Registerwcfservicecontract<g2. Sendmessage.ismsservice> (). Instanceperhttprequest ();

}

Last Call to WCF service

Private ReadOnly Ismsservice _smsservice;

_smsservice = containermanager.resolve<ismsservice> ();

AUTOFAC injection of common services and WCF services

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.