public void Singleton() { var act = EventHandlerDescriptor.Singleton <EmptyEventHandler>(); act.ActivationType.ShouldBe(EventHandlerActivationType.Singleton); act.HandlerType.ShouldBe(typeof(EmptyEventHandler)); }
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 AddSingletonHandler <TEventHandler>(this EventBusOptions options) where TEventHandler : class, IEventHandler { options.AddHandler(EventHandlerDescriptor.Singleton <TEventHandler>()); return(options); }