I am using Autofac and mediatr. The flow is a message coming from EventHub
and I process it and send it to respective command handlers. I can inject few things from the api
projects perspective, using the builder
.
builder.Register(ctx => {
var userInfo = ctx.Resolve<UserContextProvider>().GetUserInformation();
var connectionString = ResolveConnectionString(userInfo);
return new Repository(connectionString);
}).As<IRepository>();
As the messages are comming from event hub, I need to resolve those parameters dynamically. I have injected the IComponentContext
into my message processor class and am trying to resolve the parameters.
_componentContext.Resolve<ActivityCommandHandler>(new NamedParameter("conStr", ConnectionString));
When I put breakpoint on the handler constructor I can see the conStr
when the above line is executed.
Is this the correct way of doing it ?
When I send the command using _mediatr.send(mycommand)
I am getting the below exception.
None of the constructors found with
Autofac.Core.Activators.Reflection.DefaultConstructorFinder
on typeCommandHandlers.ActivityCommandHandler
can be invoked with the available services and parameters: Cannot resolve parameterSystem.String conStr
of constructorVoid .ctor(AutoMapper.IMapper, MediatR.IMediator, System.String)