在 MVC 和策略模式中按类型和注册问题解决对象

Resolving an Object by Type and Registration issue in MVC and Strategy pattern

I opened ticket last week ticket is in that ticket Brendan solution worked but once i implemented one more class and implemented IAuthStrategy on that class and registered in unity container only last register class code is executing and i want to execute each on certain condition, my new class code is

public class WindowsMechanism : IAuthStrategy
{

    private IInstitutionRepository _institutionRepository;

    public UserNamePasswordMechanism(IInstitutionRepository institutionRepository)
    {
        this._institutionRepository = institutionRepository;
    }

    public OperationResponse<AuthenticationMechanismDTO> GetAuthenticationMechanism(string userName)
    {

        throw new NotImplementedException();
    }
} 

and unity registration is this which is in unityConfig.cs

container.RegisterType<IAuthStrategy, UserNamePasswordMechanism>();
container.RegisterType<IAuthStrategy, WindowsAuthMechanism>();

i am not able to fix this issue any help will be highly appreciated.

您重写了 IAuthStrategy。您可以为已解决的

添加名称
container.RegisterType<IAuthStrategy, UserNamePasswordMechanism>("UserNamePasswordMechanish");
container.RegisterType<IAuthStrategy, WindowsAuthMechanism>("WindowsAuthMechanism");

还有他们

IAuthStrategytheDataService = container.Resolve<IAuthStrategy>("UserNamePasswordMechanish");
IAuthStrategytheLoggingService = container.Resolve<IAuthStrategy>("WindowsAuthMechanism");

你可以检查this link,如果你想