문제

I have an interface:

interface IDataHoldingSession<out T>

I want to do the following:

container.RegisterAll<IDataHoldingSession<object>>(
    typeof(IDataHoldingSession<DbContext>), 
    typeof(IDataHoldingSession<PrincipalContext>));

However, this fails with the following exception:

System.ArgumentException: The supplied type IDataHoldingSession<DbContext> does not implement IDataHoldingSession<Object>.

What's the most appropriate way to fix this?

도움이 되었습니까?

해결책

The behavior you're experiencing can be considered a bug in the current Simple Injector 2.3 release. We're working hard to ship 2.4 and I will make sure we fix this for the coming 2.4 release. There are more places in the framework where varient types aren't checked.

In the meantime, you can use the following workaround:

container.RegisterAll(typeof(IDataHoldingSession<object>),
    Lifestyle.Transient.CreateRegistration<IDataHoldingSession<object>>(
        () => container.GetInstance<IDataHoldingSession<string>>(), container),
    Lifestyle.Transient.CreateRegistration<IDataHoldingSession<object>>(
        () => container.GetInstance<IDataHoldingSession<IPlugin>>(), container));

UPDATE

Simple Injector v2.4 has been released. This release fixes this bug.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top