I want to pass an extra parameter while resolving the dependencies based on the type.
please have a look into my code changes
private readonly Func<Type,string,IManager> _strategyFactory;
calling the stratergy pattern to resolve the dependencies based on the Type.
return _strategyFactory( Type );
return _strategyFactory( Type );
Autofac Dependency changes
builder.Register<Func<Type, string, IManager>>( c =>
{
var cc = c.Resolve<IComponentContext>();
return ( Type, message ) =>
{
switch( Type )
{
case Type.A:
return cc.Resolve<AManager>(new NamedParameter( "message", "abc"));
case Type.B:
return cc.Resolve<BStatusManager>( new NamedParameter( "message", "xyz" ) );
default:
throw new ArgumentException();
}
};
} );
I am facing issue while calling the resolved class.Suppose we have a method in AManager/BManager i need to retrieve the value of the message in the constructor.
Is there any other way to retrive the message in the class
What I have tried:
Registration Concepts — Autofac 4.0 documentation[
^]