RIA Services Visual Studio 2010 Beta2中的Windsor IHandlerSelector [英] Windsor IHandlerSelector in RIA Services Visual Studio 2010 Beta2

查看:64
本文介绍了RIA Services Visual Studio 2010 Beta2中的Windsor IHandlerSelector的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用Windsor实施多租户,但我不知道如何处理这种情况:

I want to implement multi tenancy using Windsor and i don't know how to handle this situation:

我成功使用了技术在普通的ASP.NET MVC项目中并考虑到了RIA中服务项目将是类似的。

i succesfully used this technique in plain ASP.NET MVC projects and thought incorporating in a RIA Services project would be similar.

因此,我使用了IHandlerSelector,注册了一些组件并编写了ASP.NET MVC视图,以验证其在纯ASP.NET MVC环境中的正常工作。

So i used IHandlerSelector, registered some components and wrote an ASP.NET MVC view to verify it works in a plain ASP.NET MVC environment. And it did!

下一步是创建一个DomainService,该服务在构造函数中注入了IRepository。该服务托管在ASP.NET MVC应用程序中。实际上,它的工作原理是:我可以将数据提取到Silverlight应用程序中。

Next step was to create a DomainService which got an IRepository injected in the constructor. This service is hosted in the ASP.NET MVC application. And it actually ... works:i can get data out of it to a Silverlight application.

示例代码段:

public OrganizationDomainService(IRepository<Culture> cultureRepository)
{
            this.cultureRepository = cultureRepository;
}

最后一步是看它是否像多租户一样工作:不!奇怪的是:
使用一些代码行并在日志文件中写入调试消息,我确认选择了正确的处理程序!但是此处理程序似乎没有注入到DomainService中。我总是得到第一个处理程序(这是我的SelectHandler中的逻辑)

Last step is to see if it works multi-tenant-like: it does not! The weird thing is this: using some line of code and writing debug messages in a log file i verified that the correct handler is selected! BUT this handler seems not to be injected in the DomainService. I ALWAYS get the first handler (that's the logic in my SelectHandler)

有人可以验证此行为吗? RIA服务中的注入功能不起作用吗?还是我缺少一些基本的东西?

Can anybody verify this behavior? Is injection not working in RIA Services? Or am i missing something basic??

开发环境:Visual Studio 2010 Beta2

Development environment: Visual Studio 2010 Beta2

先谢谢了

推荐答案

所以看来我在OrganizationDomainServiceFactory中做了一件很奇怪的事情。
无效的代码为:

So it seems i did a very weird thing in my OrganizationDomainServiceFactory. The code which did NOT work is this:

public DomainService CreateDomainService(Type domainServiceType, DomainServiceContext context  )
{
WindsorContainer container = new WindsorContainer(new XmlInterpreter(new ConfigResource("castle")));
IRepository<Culture> cultureRepository = container.Resolve<IRepository<Culture>>();
IRepository<Currency> currencyRepository = container.Resolve<IRepository<Currency>>();

DomainService ds = (DomainService)Activator.CreateInstance(domainServiceType, new object[] { cultureRepository,currencyRepository });

ds.Initialize(context);
return ds;
}

这显然是行不通的,因为创建了一个新的Container(

This is apparently not working, because of the creation of a new Container (which should not take place).

好!所以我想我尝试使用ServiceLocator来获取对Windsor容器的引用(在WindsorControllerFactory中使用-这就是我在ASP.NET MVC应用程序的启动中称呼它的方式),并将代码更改为:

OK! So i thought i try to use ServiceLocator to get a reference to the Windsor Container (used in the WindsorControllerFactory - that's how i call it ... in the boot up of the ASP.NET MVC application), and changed the code to this:

public DomainService CreateDomainService(Type domainServiceType, DomainServiceContext context  )
{
IRepository<Culture> cultureRepository = ServiceLocator.Current.GetInstance<IRepository<Culture>>();
IRepository<Currency> currencyRepository = ServiceLocator.Current.GetInstance<IRepository<Currency>>();

DomainService ds = (DomainService)Activator.CreateInstance(domainServiceType, new object[] { cultureRepository,currencyRepository });

ds.Initialize(context);
return ds;
}

并猜猜是什么:多租户工作正常!

and guess what: it works(!!!) multi-tenancy as it should be!

我唯一不知道的是:还有另一种注入容器的方法(构造函数注入在这里似乎不起作用,编译器抱怨)

The only thing i don't know is: is there another way to "inject" the container (constructor injection seems not to work here , the compiler complains)

BTW:将项目从VS2010Beta2移至VS2010RC(在RIA Services支持下),但这不会影响结果!

BTW: moved the project from VS2010Beta2 to VS2010RC (with RIA Services support), but this should not affect the outcome!

这篇关于RIA Services Visual Studio 2010 Beta2中的Windsor IHandlerSelector的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆