I working on a project using masstransit Courier. I am trying to inject some service dependencies into my Activities but this is not working. Can someone help how to use DI in MT activity. I could not find any working example with Activity implementation and DI
In my below code I am trying to inject IMyservice into my activity. But my activity constructor is never executing. Am I doing something wrong here?
public class DownloadImageActivity :
Activity<DownloadImageArguments, DownloadImageLog>
{
public DownloadImageActivity (IMyService service)
{
_service=service;
}
Task<ExecuteResult> Execute(ExecutionContext<DownloadImageArguments> context);
Task<CompensationResult> Compensate(CompensateContext<DownloadImageLog> context);
}
my service program code ActivityService.cs
_busControl = Bus.Factory.CreateUsingRabbitMq(x =>
{
IRabbitMqHost host = x.Host(new Uri(ConfigurationManager.AppSettings["RabbitMQHost"]), h =>
{
h.Username("guest");
h.Password("guest");
});
x.ReceiveEndpoint(host, ConfigurationManager.AppSettings["completepitaskqueue"], e =>
{
e.PrefetchCount = 100;
e.ExecuteActivityHost<CompletePiTaskActivity, ComplePiTaskArguments>(Program.Container);
// e.ExecuteActivityHost(
// DefaultConstructorExecuteActivityFactory<CompletePiTaskActivity, ComplePiTaskArguments>.ExecuteFactory, c => c.UseRetry(r => r.Immediate(5)));
});
My program.cs
public static IContainer Container;
static int Main(string[] args)
{
ConfigureLogger();
Container = builder.Build();
ActivityHelper.Container = Container;
// MassTransit to use Log4Net
Log4NetLogger.Use();
return (int)HostFactory.Run(x => x.Service<ActivityService>());