开发者

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 开发者_JAVA百科DAO for each entity. i.e) 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;
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜