简体   繁体   中英

WCF service type aliases

I wonder if it's possible to define some kind of type aliases (eg as in Spring.NET ) to have shorter thus less error-prone configs, so instead of this:

<service behaviorConfiguration="ListenerBehavior" name="Corporation.Solution.Project.Namespace.GenericClass`1[[OtherCorp.Framework.Long.Class.Name, OtherCorp.Framework.Another.Long.Class.Name, Version=3.0.0.39, Culture=neutral, PublicKeyToken=null]]">
  <host>
    <baseAddresses>
      <add baseAddress="net.tcp://localhost:9485/Listener" />
    </baseAddresses>
  </host>
</service>

I would have something like this:

<service behaviorConfiguration="ListenerBehavior" name="ServiceTypeAlias">
  <host>
    <baseAddresses>
      <add baseAddress="net.tcp://localhost:9485/Listener" />
    </baseAddresses>
  </host>
</service>

Thanks.

you could go for Unity that allows you to use Type Alias

Have a look at:

http://msdn.microsoft.com/en-us/library/ff660933(PandP.20).aspx#_Type_Aliases

you have add the below to your configuration file to define the alias you want to use

<unity>
<typeAliases> 
  <typeAlias alias="MyTypeAlias" type="ProductModel.IProduct, ProductModel"/>
</typeAliases>
</unity>

The typeAlias element gives a 'short-name' for a type. This 'short-name' can be used to point to this type any where in the configuration file.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM