简体   繁体   中英

Windsor WCF Facility factory?

So I currently have a master DAO class ITrackingToolDAO that has all the Service Contracts for each of my business entities.

public partial interface ITrackingToolDAO {
    void Open(string connectionString);
    void Close();

    IBusinessFunctionDAO BusinessFunction { get; }
    IBusinessUnitDAO BusinessUnit { get; }
    IProgramBudgetDAO ProgramBudget { get; }
    IProjectDAO Project { get; }
    ...
}

My Service Contract looks like so

[ServiceContract(Namespace="http://bmgops.qintra.com/Tracking/v1/BusinessFunction")]
public partial interface IBusinessFunctionDAO {

    [OperationContract]
    BusinessFunction GetBusinessFunction(Int32 businessFunctionId);

    [OperationContract]
    IEnumerable<BusinessFunction> Find(string filter);

    [OperationContract]
    SaveEventArgs<BusinessFunction>Save(BusinessFunction businessFunction);
}

I currently have 2 concrete implementations of my ITrackingToolDAO interface. The first one is TrackingToolSqlDAO which instantiates a concrete SQL DAO for each entity. ie) BusinessFunctionSqlDAO , ProjectSqlDAO , etc.

The second one is a TrackingToolWCFDao which creates WCF proxys using ChannelFactory<T> to create an implementation for all my DAO members.

Now, I want to start using the Windsor WCF facility instead of CreateChannel. What would be the best way to accomplish this ?

I was thinking of creating a dummy implementation of ITrackingToolDAO that took in an IKernel parameter in the constructor.

public class DummyDAO: ITrackingToolDAO {
    public DummyDAO(IKernel kernel) {
        _ProjectDAO = kernel.Resolve<IProject>();
        ....
    }
}

This way i could use the WCF Facility to create all my channels. I just don't like it cuz it's using the container as a service locator which is a code smell. Ideally I would also like it if I could have my SQL DAO and new WCF DAo both registered in the container so I could create either one by just referencing them by name.

Any thoughts ?

If you're using Castle.Facilities.WcfIntegration, you could setup your dao like this:

container.Register(Component.For<IProject>().ImplementedBy<Project>());

You can than use WcfIntegration facility like this:

container.AddFacility<WcfFacility>()
    .Register(Castle.MicroKernel.Registration.Component.For<IBusinessFunctionDAO>()
    .ImplementedBy<BusinessFunctionDAO>()
    .AsWcfService());

Than for BusinessFunctionDAO you can do constructor injection like this:

public class BusinessFunctionDAO : IBusinessFunctionDAO 
{
   public BusinessFunctionDAO(IProject project)
   {
      if (project== null) new ArgumentException("project");
      _project = project;
   }
...


   private readonly IProject _project;
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM