public IEntityEventPublisher Create(IServiceProvider provider) { var context = provider.GetRequiredService <TContext>(); var messageQueue = provider.GetRequiredService <IMessageQueue>(); var uow = new EfUnitOfWork(context); return(new EntityEventPublisher( messageQueue, uow.CreateRepository <EntityEventLog, Guid>(), provider.GetService <ILogger <EntityEventPublisher> >())); }
public static IServiceCollection AddDbContextEventPublisher <TContext>(this IServiceCollection services) where TContext : DbContext, IEntityEventLogContext { services.AddScoped <IEntityEventPublisher>(provider => { var context = provider.GetRequiredService <TContext>(); var messageQueue = provider.GetRequiredService <IMessageQueue>(); var uow = new EfUnitOfWork(context); return(new EntityEventPublisher( messageQueue, uow.CreateRepository <EntityEventLog, Guid>(), provider.GetService <ILogger <EntityEventPublisher> >())); }); return(services); }