public void Transient() { var act = EventHandlerDescriptor.Transient <EmptyEventHandler>(); act.ActivationType.ShouldBe(EventHandlerActivationType.Transient); act.HandlerType.ShouldBe(typeof(EmptyEventHandler)); }
public void AddHandler() { var options = new EventBusOptions(); options.AddHandler(EventHandlerDescriptor.Transient <EmptyEventHandler>()); options.Handlers.Count.ShouldBe(1); options.Handlers.First().HandlerType.ShouldBe(typeof(EmptyEventHandler)); options.Handlers.First().ActivationType.ShouldBe(EventHandlerActivationType.Transient); }
public void GetEventHandlerFactory() { var serviceProvider = new ServiceCollection() .AddSingleton <IHybridServiceScopeFactory, DefaultServiceScopeFactory>() .AddTransient <EmptyEventHandler>() .BuildServiceProvider(); var handler = EventHandlerDescriptor.ByServiceProvider <EmptyEventHandler>() .GetEventHandlerFactory(serviceProvider).ShouldBeOfType <IocEventHandlerFactory>() .GetHandler(); handler.EventHandler.ShouldBeOfType <EmptyEventHandler>(); handler.Dispose(); EventHandlerDescriptor.Singleton <EmptyEventHandler>() .GetEventHandlerFactory(serviceProvider).ShouldBeOfType <SingleInstanceHandlerFactory>() .GetHandler().EventHandler.ShouldBeOfType <EmptyEventHandler>(); EventHandlerDescriptor.Transient <EmptyEventHandler>() .GetEventHandlerFactory(serviceProvider).ShouldBeOfType <TransientEventHandlerFactory>() .GetHandler().EventHandler.ShouldBeOfType <EmptyEventHandler>(); }
/// <summary> /// /// </summary> /// <param name="options"></param> /// <typeparam name="TEventHandler"></typeparam> /// <returns></returns> public static EventBusOptions AddTransientHandler <TEventHandler>(this EventBusOptions options) where TEventHandler : class, IEventHandler { options.AddHandler(EventHandlerDescriptor.Transient <TEventHandler>()); return(options); }