c# - Injection WCF proxy client using unity -


i have asp.net mvc application , need call wcf service in it. i've added service reference project. use unity dependency injection , want inject wcf client. it's not simple because of system.servicemodel.clientbase. did way.
autogenerated proxy:

public partial class wcfserviceclient :      system.servicemodel.clientbase<wcfunity.iwcfserviceclient>,      wcfunity.iwcfserviceclient  {     //autogenerated constructors , methods } 

i created interface:

public interface isimpleproxy : wcfunity.iwcfserviceclient {     //duplication of methods' signatures     void closeconnection(); } 

i extended wcfserviceclient using partial class:

public partial class wcfserviceclient : isimpleproxy {     public void closeconnection()     {         try         {             close();         }         catch (exception)         {             abort();         }     } } 

and inject this:

container.registertype<isimpleproxy>(new injectionfactory(c => new wcfserviceclient())); 

so don't have dependecies clientbase , there no wcf stuff inside classes use wcf proxy. solution have disadvatages?

no, doesn't, use (mostly) same approach.

i recommend making interface inherit idisposable, because underlying clientbase<t> disposable. way won't need closeconnection.


Comments

Popular posts from this blog

1111. appearing after print sequence - php -

java - WARN : org.springframework.web.servlet.PageNotFound - No mapping found for HTTP request with URI [/board/] in DispatcherServlet with name 'appServlet' -

Ruby on Rails, ActiveRecord, Postgres, UTF-8 and ASCII-8BIT encodings -