相关疑难解决方法(0)

使用StructureMap实现策略模式的最佳方式

我的Web应用程序在业务逻辑和表示逻辑上有一些细微的变化,具体取决于登录用户的类型.看起来通过根据用户类型注入不同的具体类来获得变化非常适合DI.所以我想知道我应该使用StructureMap的哪些功能来实现这一目标(或者如果我基于DI的目的而离开).

(我刚刚了解到配置文件不是实现此目的的方法,因为设置配置文件不是每线程操作:StructureMap配置文件线程安全吗?)

编辑

这是怎么回事?

public class HomeController
{
    private ISomeDependancy _someDependancy;

    public HomeController(ISomeDependancy someDependancy)
    {
        _someDependancy = someDependancy;
    }

    public string GetNameFromDependancy()
    {
        return _someDependancy.GetName();
    }
}

public interface ISomeDependancy
{
    string GetName();
}

public class VersionASomeDependancy : ISomeDependancy
{
    public string GetName()
    {
        return "My Name is Version A";
    }
}

public class VersionBSomeDependancy : ISomeDependancy
{
    public string GetName()
    {
        return "My Name is Version B";
    }
}

public class VersionARegistry : Registry
{
    public VersionARegistry() …
Run Code Online (Sandbox Code Playgroud)

.net structuremap design-patterns dependency-injection

8
推荐指数
2
解决办法
3582
查看次数