Configure Dependency | WCF Facility

55 views
Skip to first unread message

Mijo Thomas

unread,
Jun 15, 2012, 3:16:40 AM6/15/12
to castle-pro...@googlegroups.com

Hi,

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

Craig Neuwirt

unread,
Jun 15, 2012, 8:03:37 AM6/15/12
to castle-pro...@googlegroups.com
I'm probably confused, but what happens when you register IDependency/Dependency in the container?  Do you get an error?

-craig

--
You received this message because you are subscribed to the Google Groups "Castle Project Users" group.
To view this discussion on the web visit https://groups.google.com/d/msg/castle-project-users/-/oNA0FXNBI-sJ.
To post to this group, send email to castle-pro...@googlegroups.com.
To unsubscribe from this group, send email to castle-project-u...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/castle-project-users?hl=en.

Mijo Thomas

unread,
Jun 15, 2012, 9:30:22 AM6/15/12
to castle-pro...@googlegroups.com
Hi,

The service is not started. It says stopped and is in errored state. It says "Cannot start because the dependency is not satisfied".

Thanks,
-Mike

Craig Neuwirt

unread,
Jun 15, 2012, 9:33:45 AM6/15/12
to castle-pro...@googlegroups.com
But  where in your ConfigureContainer.AndRegisterComponents do you register IDependency

container.Register(Component.For<IDependency>().ImplementedBy<Dependency>())

Is it registered somewhere else?

Mijo Thomas

unread,
Jun 15, 2012, 11:08:39 AM6/15/12
to castle-pro...@googlegroups.com
Hi,

It's registered in the same place. I'm attaching a very basic sample for you which does not work.

I'm trying to host a WCF service(over TCP) inside a Windows Service and using Castle Windsor facility. As you could see in the sample, when I launch it in debug mode, the service crashes.

Thanks for your help in advance.

Kind Regards,
- Mike
Sample.zip

Mijo Thomas

unread,
Jun 16, 2012, 6:53:18 PM6/16/12
to castle-pro...@googlegroups.com
Hi,

Sorry to bother you, but please did you figure out what was wrong with it?

Thanks,
-Mike
Reply all
Reply to author
Forward
0 new messages