Dependency Injection Unity - Conditional Resolving

2019-08-24 01:10发布

I'm following this great answer for Conditional Resolving in Dependency Inject by @NightOwl888

He used to register the Dependency Injections using Code like below

// Note that the strings used here for instance names have nothing 
// to do with the strings used to select the instance in the strategy pattern
unityContainer.RegisterType<IAuthenticate, TwitterAuth>("twitterAuth");
unityContainer.RegisterType<IAuthenticate, FacebookAuth>("facebookAuth");
unityContainer.RegisterType<IAuthenticateStrategy, AuthenticateStrategy>(
    new InjectionConstructor(
        new ResolvedArrayParameter<IAuthenticate>(
            new ResolvedParameter<IAuthenticate>("twitterAuth")
        ),
        new ResolvedArrayParameter<IAuthenticate>(
            new ResolvedParameter<IAuthenticate>("facebookAuth")
        )
    ));

But I'd like to implement the above through web.config. So that my change would be just a configuration and not code changes

So far I can able to get only simple implementation like here

0条回答
登录 后发表回答