Example #1
0
        public void Transient()
        {
            var act = EventHandlerDescriptor.Transient <EmptyEventHandler>();

            act.ActivationType.ShouldBe(EventHandlerActivationType.Transient);
            act.HandlerType.ShouldBe(typeof(EmptyEventHandler));
        }
Example #2
0
        public void Singleton()
        {
            var act = EventHandlerDescriptor.Singleton <EmptyEventHandler>();

            act.ActivationType.ShouldBe(EventHandlerActivationType.Singleton);
            act.HandlerType.ShouldBe(typeof(EmptyEventHandler));
        }
Example #3
0
        public void ByServiceProvider()
        {
            var act = EventHandlerDescriptor.ByServiceProvider <EmptyEventHandler>();

            act.ActivationType.ShouldBe(EventHandlerActivationType.ByServiceProvider);
            act.HandlerType.ShouldBe(typeof(EmptyEventHandler));
        }
Example #4
0
        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));
        }
Example #5
0
        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);
        }
Example #6
0
        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>();
        }
Example #7
0
 /// <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);
 }
Example #8
0
 /// <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);
 }
Example #9
0
 /// <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);
 }
Example #10
0
 /// <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);
 }
Example #11
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="handlerDescriptor"></param>
 public void AddHandler(EventHandlerDescriptor handlerDescriptor)
 {
     Handlers.Add(handlerDescriptor);
 }