I am trying to configure some properties of a concrete implementation of a service that has some properties set to different values depending on which profile is selected at startup, but NSB doesn't seem to allow configuration of properties on the implementation of an interface. We are using Castle Windsor for the container, if that's relevant.
We set up the container initially with a service installer that is run from the EndpointConfig class like this:
public class EndpointConfig : IConfigureThisEndpoint,
AsA_Publisher,
IWantCustomInitialization
{
public void Init()
{
Configure.With()
.CastleWindsorBuilder(CreateContainer(new ServiceInstaller()))
.UnicastBus()
.XmlSerializer()
;
}
protected WindsorContainer CreateContainer(IWindsorInstaller installer)
{
var container = new WindsorContainer();
container.Register(Component.For<IWindsorContainer>().Instance(container));
container.Install(installer);
container.Kernel.ReleasePolicy = new Castle.MicroKernel.Releasers.NoTrackingReleasePolicy();
return container;
}
}
public class ServiceInstaller : IWindsorInstaller
{
public void Install(IWindsorContainer container, IConfigurationStore store)
{
container.Register(Component.For<IService>().ImplementedBy<ServiceAdapter>());
// ...
}
}
ServiceAdapter has some string properties that aren't in the interface that need different settings depending on which profile is selected:
public interface IService
{
}
public class ServiceAdapter : IService
{
public string Url;
}
The profile handler does:
Configure.Instance.Configurer.ConfigureProperty<ServiceAdapter>
(x => x.Url, "http://url.goes.here");
but when the profile is loaded, it throws System.InvalidOperationException: Cannot configure property for a type which hadn't been configured yet. Please call 'Configure' first.
.
Is it possible to do property injection on the concrete implementation without adding the properties into the interface?