0

I opened ticket last week ticket is Asp.Net MVC and Strategy pattern 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.

Community
  • 1
  • 1
BraveBoy
  • 117
  • 1
  • 14

1 Answers1

0

You rewrote IAuthStrategy. You can add name for resolved

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

And them

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

You can check this link, if you want

Dmitresky
  • 536
  • 8
  • 21