什么是实现使用温莎城堡在ASP.NET MVC多租户技术的最佳做法? [英] What is the best practice to implement multi tenancy in ASP.NET MVC using Castle Windsor?

查看:451
本文介绍了什么是实现使用温莎城堡在ASP.NET MVC多租户技术的最佳做法?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有两个不同的实现的服务,我想注入控制器构造,取决于标准(目前的标准是存储在会话一个简单的值)。

I have a service with two different implementations and I would like to inject into the controllers constructor, depends on a criteria (at the moment the criteria is a simple value stored in session).

这是我现在得到...

Here is what I got now...

Service接口:

Service interface:

public interface IService
{
    string GetSampleText();
}

实施1:

public class FirstService : IService
{
    string GetSampleText()
    {
        return "First Service";
    }
}

实施2:

public class SecondService : IService
{
    string GetSampleText()
    {
        return "Second Service";
    }
}

在注册温莎一个安装程序类:

Registration in a Windsor installer class:

container.Register(AllTypes
  .FromAssemblyInDirectory(new AssemblyFilter(HttpRuntime.BinDirectory))
  .BasedOn<IService>()
  .WithService.FromInterface()
  .Configure(c => c.LifeStyle.Transient));

container.Kernel.AddHandlerSelector(new ServiceHandlerSelector());

我已经实现了IHandlerSelector:

I have implemented an IHandlerSelector:

public class ServiceHandlerSelector : IHandlerSelector { ... }

在此IHandlerSelector实现我可以决定哪些处理程序将在每个所选的方法进行选择的方法HasOpinionAbout(依赖于从会话的值)。

In the HasOpinionAbout method of this IHandlerSelector implementation I can decide which handler will be selected in the SelectHandler method (depends on the value from session).

然后构造注入工作正常的控制器:

Then the constructor injection is working fine on the controllers:

public MyController(IService service) { ... }

所以,我得到了一个有效的解决方案,但我不知道这是否是做到这一点的最好办法。

So I got a working solution, but I am not sure if it is the best way to do this.

意见?建议?

非常感谢。

推荐答案

您是在正确的轨道与处理程序上的选择。以下是使用他们的多租户一些好文章,你可以使用它们,以供参考:

You're on the right track with handler selectors. Here are some good articles on using them for multi-tenancy, you can use them for reference:

这篇关于什么是实现使用温莎城堡在ASP.NET MVC多租户技术的最佳做法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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