English 中文(简体)
服务解决/占用和参数
原标题:Service Resolution/Location and Parameters

你们如何通过参数,让决心者制造物体?

我有一只紫外线物体,我想将其输入一个数据服务物体,我希望能够确保使用一个UoW物体制作特定序列的数据服务物体。

for example

using (var context = Resolver.GetService<IUoW>())
{
    var dataService1 = Resolver.GetService<IDataService1>();
    var dataService2 = Resolver.GetService<IDataService2>();

    // do some stuff

    context.Commit();
}

Option 1, pass IUoW into the Resolver.GetService call - there is no knowledge of the constructors for IDataServiceX implementations

Option 2, add a property to IDataServiceX for IUoW - not setting it would be easily done, how would a programmer know this property was required to be set

最佳回答

我以前曾执行过一个工作单位和实体框架的托存模式。

In reality the UoW abstracted the EF context, and the repositories abstracted the entity sets.

In my implementation of the Repositories were properties of the UoW, meaning it was not the IoC container that managed the life-cycle of the repositories, that was the responsibility of the UoW.

In your situation the repositories are named services, but maybe the same applies. Can the IUoW interface have two (or more) properties for all the services that exist within the specific unit of work?

问题回答

暂无回答




相关问题
how to mock container.Resolve<Type>()

i have a something like this public class HomeController { public ActionResult Index() { var x = Container.Resolve<IOrganisationService>(); } } when unit testing i get a null ...

How to Inject Open Connections with an IoC

First, my scenario. I have a service, BillingService, has a constructor like this: BillingService(IInstallmentService, IBillingRepository) The InstallmentService has a constructor that looks like ...

IoC container object scoping

I am interested in implementing an IoC container in my project but I haven t seen an example out there that does what I need. Here is the situation, my application is built in WPF and uses the MVVM ...

Should I encapsulate my IoC container?

I m trying to decide whether or not it makes sense to go through the extra effort to encapsulate my IoC container. Experience tells me that I should put a layer of encapsulation between my apps and ...

How can I override a component registered in Castle Windsor?

I m just starting with Windsor, so please be gentle :) I have a scenario where I want to be able to override/replace components placed inside a windsor container. Read on ... In my prod code, I want ...

热门标签