Hi I'm trying to get dependency injection to work using Castle Windsor in a console app to host WCF service in Azure using the example in:
https://azure.microsoft.com/en-gb/documentation/articles/service-bus-dotnet-how-to-use-relay/
My WCF service works fine using Castle Windsor (Small sample):
public class PersonService : IPersonService
{
private readonly IPersonManager _personManager;
public PersonService(IPersonManager personManager)
{
_personManager = personManager;
}
public Message Create(Person person)
{
Message result = _ personManager.Create(person);
}
}
Castle Windsor (in wcf service Global.asax)
private void BuildWindsorContainer ()
{
var container = new WindsorContainer();
container.Kernel.AddFacility<WcfFacility>();
container.Kernel.Register(
Component.For< IPersonManager >().ImplementedBy<PersonManager >(),
Component.For<IPersonService>()
.ImplementedBy<PersonService>()
.Named("WebS.PersonService"),
);
}
In My hosted Client which calls the WCF service I have:
private static ServiceHost CallPersonService()
{
BuildWindsorContainer ();
var sh = new ServiceHost(typeof (PersonService));
sh.AddServiceEndpoint(typeof (IPersonService), new NetTcpBinding(), "net.tcp://localhost:37050/person");
sh.AddServiceEndpoint(typeof (IPersonService), new NetTcpRelayBinding(),
ServiceBusEnvironment.CreateServiceUri("sb", ServiceNamespace, "person"))
.Behaviors.Add(new TransportClientEndpointBehavior
{
TokenProvider =
TokenProvider.CreateSharedAccessSignatureTokenProvider("RootManageSharedAccessKey", Key)
});
private void BuildWindsorContainer ()
{
var container = new WindsorContainer();
container.Kernel.AddFacility<WcfFacility>();
container.Kernel.Register(
Component.For< IPersonManager >().ImplementedBy<PersonManager >(),
Component.For<IPersonService>()
.ImplementedBy<PersonService>()
.Named("WebS.PersonService"),
);
}
How do I get the dependencies to be injected into service from the client?
var sh = new ServiceHost(typeof (PersonService));
sh.AddServiceEndpoint(typeof (IPersonService), new NetTcpBinding(), "net.tcp://localhost:37050/person");
IPersonManager is null in service when the client runs.