Configuring WCF dependencies

I'm trying to host my WCF service in a windows service host. For managing dependencies I'm using Castle WCF facility.

This is how my ContainerConfiguration(BootStrapper) looks like:

 public class ConfigureContainer : IConfigureContainer
        {
            private const string ServiceOne= "ServiceOne";
            private const string ServiceTwo      = "ServiceTwo";
            private const string ServiceThree = "ServiceThree";
            private const string CurrentAssembly      = "MyAssembly";

            private readonly IWindsorContainer container;

            public ConfigureContainer(IWindsorContainer container)
            {
                this.container = container;
            }


            public IWindsorContainer WindsorContainer { get { return container; } }


            public void AndRegisterComponents()
            {
                container.Register(AllTypes.FromAssemblyNamed(CurrentAssembly)
                       .Pick().If(type => type.GetInterfaces().Any(i => i.IsDefined(typeof(ServiceContractAttribute), true)))
                       .Configure(configurer => configurer
                                                    .Named(configurer.Implementation.Name)
                                                    .AsWcfService(
                                                        new DefaultServiceModel()
                                                            .AddEndpoints(
                                                                WcfEndpoint.FromConfiguration(ServiceOne),
                                                                WcfEndpoint.FromConfiguration(ServiceTwo),
                                                                WcfEndpoint.FromConfiguration(ServiceThree))
                                                                .PublishMetadata()))
                       .WithService.Select((type, baseTypes) => type.GetInterfaces()
                           .Where(i => i.IsDefined(typeof(ServiceContractAttribute), true))));

            }
        }

This is how I do my hosting inside the service host:

partial class DataServicesHost : ServiceBase
    {
        private IWindsorContainer windsorContainer;
        public DataServicesHost()
        {
            InitializeComponent();
        }

        protected override void OnStart(string[] args)
        {
            var configure = new ConfigureContainer();
            windsorContainer = configure.WindsorContainer;
        }

        protected override void OnStop()
        {
           if(windsorContainer != null)
           {
             windsorContainer.Dispose();
             windsorContainer = null;
           }
        }
    }

My ServiceOne is implemented as follows:

[ServiceContract]
    internal interface IServiceOne
    {
        [OperationContract]
        void DoSomething();
    }

    public class ServiceOne : IServiceOne
    {
        private readonly IDependency dependency;

        public ServiceOne(IDependency dependency)
        {
            this.dependency = dependency;
        }

        public void DoSomething()
        {
            dependency.GetSomething();
            //do something
        }
    }

    public interface IDependency
    {
        void GetSomething();
    }

    public class Dependency : IDependency
    {
        public void GetSomething()
        {
            //GetSomeThing
        }
}

Now my question is: how do I pass the IDependency to the container? How will I configure it so that while hosting it, it does't complain about not letting the host know of the dependency and keeps looking and failing over the default constructor implementation?

Thanks, -Mike

Answers


You need to spin up the Windsor container for the WCF service inside the WCF ServiceHost not the Windows service code. Look at these two blog posts on the Castle WCF facility and WCF in a Windows Service to see what you'll need to do. Basically, the Windows service code just spins up a WCF ServiceHostFactory that you get from the Castle WCF facility and that factory is what actually configures the Castle container.


Need Your Help

HTML5 Canvas - Adding more circles rotate in circular motion

javascript html5 canvas rotation circle

I am trying to add a few more circles in the circular loop using HTML5 canvas but it doesn't seem to work. I want the other circles to kind of trail the circle is already rotating there. I am also

Windows Live Messenger connection via Javascript

javascript xmpp windows-live-messenger messenger

I have given up on solving this one on my own, and any help would be greatly appreciated.