Exemplo n.º 1
0
        public static ClientCofiguration AddType(this ClientCofiguration config, Type type)
        {
            foreach (var @interface in type.GetInterfaces())
            {
                if ([email protected])
                {
                    continue;
                }

                var genericDefinition = @interface.GetGenericTypeDefinition();

                if (genericDefinition == typeof(IReadModel <,>))
                {
                    AddReadModel(config, type, @interface);
                    continue;
                }

                if (genericDefinition != typeof(ICancellableCommandHandler <>) && genericDefinition != typeof(ICancellableEventHandler <>) &&
                    genericDefinition != typeof(ICommandHandler <>) && genericDefinition != typeof(IEventHandler <>) &&
                    genericDefinition != typeof(ISpecificationCommandHandler <>))
                {
                    continue;
                }

                var name = @interface.GetGenericArguments()[0].Name;

                config.RegisterHandler(name, type);
            }

            return(config);
        }
Exemplo n.º 2
0
        public static ClientCofiguration AddReadModel <TModel, TRespond, TQuery>(this ClientCofiguration configuration)
            where TModel : IReadModel <TRespond, TQuery> where TQuery : IQuery <TRespond>
        {
            AddReadModel(configuration, typeof(TModel), typeof(IReadModel <TRespond, TQuery>));

            return(configuration);
        }
Exemplo n.º 3
0
        private static void ScanFrom(ClientCofiguration config, Type targetType)
        {
            var asm = targetType.Assembly;

            foreach (var type in asm.GetTypes())
            {
                if (!type.IsDefined(typeof(CQRSHandlerAttribute), false))
                {
                    continue;
                }

                config.AddType(type);
            }
        }
Exemplo n.º 4
0
        public static ClientCofiguration AddAwaiter <TRespond>(this ClientCofiguration clientCofiguration) where TRespond : IEvent
        {
            //serviceCollection.AddTransient<AwaiterBase<TMessage, TRespond>, SimpleAwaiter<TMessage, TRespond>>();

            if (clientCofiguration.IsHandlerRegistrated <TRespond, GlobalEventHandler <TRespond> >())
            {
                return(clientCofiguration);
            }

            //serviceCollection.TryAddSingleton<GlobalEventHandler<TRespond>, GlobalEventHandler<TRespond>>();
            clientCofiguration.RegisterEventHandler <TRespond, GlobalEventHandler <TRespond> >();

            return(clientCofiguration);
        }
Exemplo n.º 5
0
        public static void AddCQRSServices(this IServiceCollection services, Action <ClientCofiguration> config)
        {
            var clientCofiguration = new ClientCofiguration();

            services.TryAddSingleton <IOptions <ClientCofiguration> >(new OptionsWrapper <ClientCofiguration>(clientCofiguration));
            config(clientCofiguration);

            //Dynamic TypeHandling for Serialization
            //services.AddCQRSTypeHandling();

            //Client for the Dispatcher
            services.TryAddSingleton <ISnapshotStore, SnapshotServerStore>();
            services.TryAddSingleton <IEventStore, ServerEventStore>();
            services.TryAddSingleton <IDispatcherClient, DispatcherClient>();
            services.TryAddTransient <IDispatcherApi, DispatcherApi>();
            services.TryAddSingleton <ICache, MemoryCache>();

            services.TryAddSingleton(typeof(GlobalEventHandler <>), typeof(GlobalEventHandler <>));
            services.TryAddScoped(typeof(QueryAwaiter <>), typeof(QueryAwaiter <>));
            services.TryAddTransient(typeof(AwaiterBase <,>), typeof(SimpleAwaiter <,>));
            services.TryAddTransient <IAwaiterFactory, AwaiterFactory>();

            //Service Delegates for cqrs lite
            services.TryAddScoped <ICommandSender, CommandSender>();
            services.TryAddScoped <IEventPublisher, EventPublisher>();
            services.TryAddSingleton <IHandlerManager, HandlerManager>();
            services.TryAddScoped <IQueryProcessor, QueryProcessor>();

            //Processing and Data Services
            services.TryAddSingleton(typeof(IPersistApi),
                                     provider => new RestEase.RestClient(provider.GetRequiredService <IOptions <ClientCofiguration> >().Value.PersistenceApiUrl).For <IPersistApi>());

            services.AddScoped <ISession, CqrsSession>();
            services.AddScoped <IRepository>(s =>
            {
                var store    = s.GetRequiredService <IEventStore>();
                var snapshot = s.GetRequiredService <ISnapshotStore>();

                return(new CacheRepository(
                           new SnapshotRepository(
                               snapshot, s.GetService <ISnapshotStrategy>() ?? new DefaultSnapshotStrategy(),
                               new InternalRepository(store), store), store, s.GetRequiredService <ICache>()));
            });
        }
Exemplo n.º 6
0
 public static void AddReadModel(ClientCofiguration configuration, Type readModel, Type @interface)
 => configuration.RegisterHandler(@interface.GetGenericArguments()[0].FullName, readModel);
Exemplo n.º 7
0
 public static ClientCofiguration AddFrom <TType>(this ClientCofiguration config)
 {
     ScanFrom(config, typeof(TType));
     return(config);
 }
Exemplo n.º 8
0
 public static void AddFrom <TType>(this IServiceCollection serviceCollection, ClientCofiguration config)
 => ScanFrom(config, typeof(TType));