You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Simple Injector blocks the application of both Scoped decorators and proxy decorators to container uncontrolled collections. However, when such decorator registration is made using the overload that takes in a decorator type factory, Simple Injector throws a rather obscure NullReferenceException, instead of throwing the expected descriptive exception.
The following tests reproduce the issue:
sealedclassPluginProxy:IPlugin{publicPluginProxy(Func<IPlugin>pluginFactory){}}sealedclassPluginDecorator:IPlugin{publicPluginDecorator(IPluginplugin){}}[TestMethod]publicvoidTest1(){// Actvarcontainer=new Container();IEnumerable<IPlugin>collection=new[]{new PluginImpl()};
container.Collection.Register(containerUncontrolledCollection: collection);
container.RegisterDecorator(typeof(IPlugin),_ =>typeof(PluginProxy),// factory returning (func-wrapping) proxy
Lifestyle.Transient,_ =>true);// ActActionaction=()=> container.Verify();// Currently fails with a NullReferenceException// Assert
AssertThat.ThrowsWithExceptionMessageContains<InvalidOperationException>("It's impossible for the container to generate a Func<IPlugin> for injection into the "+"PluginProxy decorator that will be wrapped around instances of the collection of IPlugin "+"instances",
action);}[TestMethod]publicvoidTest2(){// Actvarcontainer=new Container();
container.Options.DefaultScopedLifestyle =new AsyncScopedLifestyle();IEnumerable<IPlugin>collection=new[]{new PluginImpl()};
container.Collection.Register(containerUncontrolledCollection: collection);
container.RegisterDecorator(typeof(IPlugin),_ =>typeof(PluginDecorator),// using factory
Lifestyle.Scoped,// lifestyle other than singleton or transient_ =>true);// ActActionaction=()=> container.Verify();// Currently fails with a NullReferenceException// Assert
AssertThat.ThrowsWithExceptionMessageContains<InvalidOperationException>("You are trying to apply the PluginDecorator decorator with the 'Async Scoped' lifestyle "+"to a collection of type IPlugin, but the registered collection is not controlled by the "+"container.",
action);}
The text was updated successfully, but these errors were encountered:
Simple Injector blocks the application of both
Scoped
decorators and proxy decorators to container uncontrolled collections. However, when such decorator registration is made using the overload that takes in a decorator type factory, Simple Injector throws a rather obscureNullReferenceException
, instead of throwing the expected descriptive exception.The following tests reproduce the issue:
The text was updated successfully, but these errors were encountered: