Click here to Skip to main content
15,886,777 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I want to pass an extra parameter while resolving the dependencies based on the type.

please have a look into my code changes

C#
private readonly Func<Type,string,IManager> _strategyFactory;


calling the stratergy pattern to resolve the dependencies based on the Type.
return _strategyFactory( Type );
C#
return _strategyFactory( Type );


Autofac Dependency changes
C#
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[^]
Posted

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900