Let's say we want to consume WCF-service in our ASP.NET MVC application. We try to keep clean design, and we want to inject our dependent WCF service, say, in our MVC Controller.
For example:
To accomplish this we need new version of Castle Windsor container. You need to create WindsorContainer, add Castle WCFWacility, and then register your service.
It may looks like this(in your Global.asax Application_Start handler):
For example:
public class MyController : Controller
{
private readonly IAnonymousService _anonymousService;
public MyController(IAnonymousService anonymousService)
{
_anonymousService = anonymousService;
}
}
To accomplish this we need new version of Castle Windsor container. You need to create WindsorContainer, add Castle WCFWacility, and then register your service.
It may looks like this(in your Global.asax Application_Start handler):
Container = new WindsorContainer();
Container.AddFacility<WcfFacility>();
var anonumousServiceUrl = ConfigurationManager.AppSettings["AnonymousServiceUrl"];
Container.Register(Component.For<IAnonymousService>().AsWcfClient(WcfEndpointBoundTo(new BasicHttpBinding()).At(anonumousServiceUrl)));
No comments:
Post a Comment