public void Transient() { var act = EventHandlerDescriptor.Transient <EmptyEventHandler>(); act.ActivationType.ShouldBe(EventHandlerActivationType.Transient); act.HandlerType.ShouldBe(typeof(EmptyEventHandler)); }
public void Singleton() { var act = EventHandlerDescriptor.Singleton <EmptyEventHandler>(); act.ActivationType.ShouldBe(EventHandlerActivationType.Singleton); act.HandlerType.ShouldBe(typeof(EmptyEventHandler)); }
public void ByServiceProvider() { var act = EventHandlerDescriptor.ByServiceProvider <EmptyEventHandler>(); act.ActivationType.ShouldBe(EventHandlerActivationType.ByServiceProvider); act.HandlerType.ShouldBe(typeof(EmptyEventHandler)); }
public void Describe() { Should.Throw <ArgumentException>(() => EventHandlerDescriptor.Describe(typeof(object), EventHandlerActivationType.Singleton)); var act = EventHandlerDescriptor.Describe(typeof(EmptyEventHandler), EventHandlerActivationType.Singleton); act.ActivationType.ShouldBe(EventHandlerActivationType.Singleton); 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); }
/// <summary> /// /// </summary> /// <param name="options"></param> /// <typeparam name="TEventHandler"></typeparam> /// <returns></returns> public static EventBusOptions AddSingletonHandler <TEventHandler>(this EventBusOptions options) where TEventHandler : class, IEventHandler { options.AddHandler(EventHandlerDescriptor.Singleton <TEventHandler>()); return(options); }
/// <summary> /// /// </summary> /// <param name="options"></param> /// <param name="activationType"></param> /// <typeparam name="TEventHandler"></typeparam> /// <returns></returns> public static EventBusOptions AddHandler <TEventHandler>(this EventBusOptions options, EventHandlerActivationType activationType) where TEventHandler : class, IEventHandler { options.AddHandler(EventHandlerDescriptor.Describe <TEventHandler>(activationType)); return(options); }
/// <summary> /// /// </summary> /// <param name="options"></param> /// <param name="handlerType"></param> /// <param name="activationType"></param> /// <returns></returns> public static EventBusOptions AddHandler(this EventBusOptions options, Type handlerType, EventHandlerActivationType activationType) { options.AddHandler(EventHandlerDescriptor.Describe(handlerType, activationType)); return(options); }
/// <summary> /// /// </summary> /// <param name="handlerDescriptor"></param> public void AddHandler(EventHandlerDescriptor handlerDescriptor) { Handlers.Add(handlerDescriptor); }