internal static IServiceCollection AddInstanceSingleton <TInterface, TImplementation>(this IServiceCollection services, IEnumerable <string> routePatterns, string?exchange, int order)
            where TInterface : class
            where TImplementation : class, TInterface
        {
            var patterns = routePatterns.ToList();

            services.AddSingleton <TInterface, TImplementation>();
            var router = new MessageHandlerRouter(typeof(TImplementation), exchange, patterns);

            services.Add(new ServiceDescriptor(typeof(MessageHandlerRouter), router));
            return(services.AddMessageHandlerOrderingModel <TImplementation>(patterns, exchange, order));
        }
        internal static IServiceCollection AddInstanceTransient <TInterface, TImplementation>(this IServiceCollection services, IEnumerable <string> routePatterns, string exchange, int order)
            where TInterface : class
            where TImplementation : class, TInterface
        {
            services.AddTransient <TInterface, TImplementation>();
            var router = new MessageHandlerRouter
            {
                Type          = typeof(TImplementation),
                Exchange      = exchange,
                RoutePatterns = routePatterns.ToList()
            };

            services.Add(new ServiceDescriptor(typeof(MessageHandlerRouter), router));
            services.AddMessageHandlerOrderingModel <TImplementation>(routePatterns, exchange, order);
            return(services);
        }
예제 #3
0
        async Task CreateProjectionFromEvents <TProjection>(IEnumerable <SourcedEvent> events, Action <TProjection> onLoaded) where TProjection : new()
        {
            var projection = new TProjection();

            var router = new MessageHandlerRouter();

            router.RegisterHandler(projection);

            foreach (var e in events)
            {
                await router.RouteMessageToHandlersAsync(e.Body);
            }

            router.UnregisterHandler(projection);
            onLoaded(projection);
        }
        public ProjectionHydrater(EventRetreiver eventRetreiver)
        {
            this.eventRetreiver = eventRetreiver;

            eventRouter = new MessageHandlerRouter();
        }