Я использую azure event hub, и я пытаюсь выяснить, как передать зависимости в классе EventProcessor, используемом для обработки событий вне центра событий в моей рабочей роли , Этот класс наследует .net-интерфейс IEventProcessor.Azure - Structuremap. Как передать зависимость к классу, который реализует IEventProcessor (Event Hub)
Ниже показан мой процессор обработки событий. Я борюсь с использованием структурной карты, чтобы внедрить OrchestrationService и ее зависимости через сквозную инъекцию конструктора.
Любые предложения будут с благодарностью приняты :-)
public class EventHubEventProcessor : IEventProcessor
{
private readonly IOrchestrationService _orchestrationService;
private readonly IEventReceiver _eventReceiver;
IDictionary<string, int> map;
PartitionContext partitionContext;
Stopwatch checkpointStopWatch;
public EventHubEventProcessor(IOrchestrationService orchestrationService)
{
_orchestrationService = orchestrationService;
}
public Task OpenAsync(PartitionContext context)
{
Console.WriteLine(string.Format("SimpleEventProcessor initialize. Partition: '{0}', Offset: '{1}'", context.Lease.PartitionId, context.Lease.Offset));
this.partitionContext = context;
this.checkpointStopWatch = new Stopwatch();
this.checkpointStopWatch.Start();
return Task.FromResult<object>(null);
}
public async Task ProcessEventsAsync(PartitionContext context, IEnumerable<EventData> events)
{
try
{
foreach (EventData eventData in events)
{
_orchestrationService.Orchestrate(eventData);
Console.WriteLine("Processed Event " + eventData.PartitionKey);
}
//Call checkpoint every 5 minutes, so that worker can resume processing from the 5 minutes back if it restarts.
if (this.checkpointStopWatch.Elapsed > TimeSpan.FromMinutes(5))
{
await context.CheckpointAsync();
this.checkpointStopWatch.Restart();
}
}
catch (Exception exp)
{
Console.WriteLine("Error in processing: " + exp.Message);
}
}
public async Task CloseAsync(PartitionContext context, CloseReason reason)
{
Console.WriteLine(string.Format("Processor Shuting Down. Partition '{0}', Reason: '{1}'.", this.partitionContext.Lease.PartitionId, reason.ToString()));
if (reason == CloseReason.Shutdown)
{
await context.CheckpointAsync();
}
}
}
}