コード例 #1
0
 protected virtual IEnumerable <DiscoveredModel> DiscoverCustomLogic(DiscoveryContext context)
 {
     yield return(new DiscoveredModel(typeof(IMigrationCustomLogic), typeof(NoCustomLogic), ServiceLifetime.Transient)
     {
         CanOverrideDefaults = true
     });
 }
コード例 #2
0
        protected override IEnumerable <DiscoveredModel> GetModels(DiscoveryContext context)
        {
            var models = base.GetModels(context).ToList();

            models.Add(new DiscoveredModel(typeof(Projections.Versioning.ProjectionHasher), typeof(Projections.Versioning.ProjectionHasher), ServiceLifetime.Singleton));

            return(models);
        }
コード例 #3
0
        protected virtual IEnumerable <DiscoveredModel> DiscoverCronusStartups(DiscoveryContext context)
        {
            foreach (var startupType in context.Assemblies.Find <ICronusStartup>())
            {
                yield return(new DiscoveredModel(startupType, startupType, ServiceLifetime.Singleton));
            }

            yield return(new DiscoveredModel(typeof(Cronus.ProjectionsStartup), typeof(Cronus.ProjectionsStartup), ServiceLifetime.Transient)); // TODO: Check if this is alrady registered in the foreach above. If yes we can remove this line. Elase we have to figure out what is going on
        }
コード例 #4
0
        public IDiscoveryResult <TCronusService> Discover()
        {
            DiscoveryContext context = new DiscoveryContext();

            context.Configuration = Configuration;
            context.Assemblies    = AssemblyLoader.Assemblies.Values;
            var discoveryResult = DiscoverFromAssemblies(context);

            return(discoveryResult);
        }
コード例 #5
0
        protected override DiscoveryResult <IEventStore> DiscoverFromAssemblies(DiscoveryContext context)
        {
            IEnumerable <DiscoveredModel> models = DiscoverIndices(context)
                                                   .Concat(new[] {
                new DiscoveredModel(typeof(IEventStoreInterceptor), typeof(NoAggregateCommitTransformer), ServiceLifetime.Singleton),
                new DiscoveredModel(typeof(NoAggregateCommitTransformer), typeof(NoAggregateCommitTransformer), ServiceLifetime.Singleton),
                new DiscoveredModel(typeof(EventStoreFactory), typeof(EventStoreFactory), ServiceLifetime.Scoped)
            });

            return(new DiscoveryResult <IEventStore>(models));
        }
コード例 #6
0
        protected override DiscoveryResult <ICronusHost> DiscoverFromAssemblies(DiscoveryContext context)
        {
            IEnumerable <DiscoveredModel> models =
                DiscoverCronusHost(context)
                .Concat(DiscoverCronusStartups(context))
                .Concat(DiscoverCommands(context))
                .Concat(DiscoverEvents(context))
                .Concat(DiscoverPublicEvents(context))
                .Concat(DiscoverSignals(context))
                .Concat(DiscoverMigrations(context));

            return(new DiscoveryResult <ICronusHost>(models));
        }
コード例 #7
0
        protected virtual IEnumerable <DiscoveredModel> GetModels(DiscoveryContext context)
        {
            var foundTypes = context.FindService <T>();

            foreach (var type in foundTypes)
            {
                yield return(new DiscoveredModel(type, type, ServiceLifetime.Transient));
            }

            yield return(new DiscoveredModel(typeof(TypeContainer <T>), new TypeContainer <T>(foundTypes)));

            yield return(new DiscoveredModel(typeof(IHandlerFactory), provider => new DefaultHandlerFactory(type => provider.GetRequiredService(type)), ServiceLifetime.Transient));
        }
コード例 #8
0
        protected virtual IEnumerable <DiscoveredModel> GetModels(DiscoveryContext context)
        {
            var loadedTypes = context.Assemblies.SelectMany(asm => asm.GetLoadableTypes())
                              .Where(type => type.IsAbstract == false && type.IsInterface == false && typeof(T).IsAssignableFrom(type));

            foreach (var type in loadedTypes)
            {
                yield return(new DiscoveredModel(type, type, ServiceLifetime.Transient));
            }

            yield return(new DiscoveredModel(typeof(TypeContainer <T>), new TypeContainer <T>(loadedTypes)));

            yield return(new DiscoveredModel(typeof(IHandlerFactory), provider => new DefaultHandlerFactory(type => provider.GetRequiredService(type)), ServiceLifetime.Transient));
        }
コード例 #9
0
        public IEnumerable <IDiscoveryResult <object> > Scan(DiscoveryContext context)
        {
            var discoveries = context.Assemblies
                              .SelectMany(asm => asm
                                          .GetLoadableTypes()
                                          .Where(type => type.IsAbstract == false && type.IsClass && typeof(IDiscovery <object>).IsAssignableFrom(type)))
                              .Select(dt => (IDiscovery <object>)FastActivator.CreateInstance(dt));

            foreach (var discovery in discoveries)
            {
                logger.Info(() => $"Discovered {discovery.Name}");

                yield return(discovery.Discover(context));
            }
        }
コード例 #10
0
        IEnumerable <DiscoveredModel> GetModels(DiscoveryContext context)
        {
            foreach (var startupType in context.Assemblies.Find <ICronusStartup>())
            {
                yield return(new DiscoveredModel(startupType, startupType, ServiceLifetime.Singleton));
            }


            yield return(new DiscoveredModel(typeof(ICronusHost), typeof(CronusHost), ServiceLifetime.Transient));

            yield return(new DiscoveredModel(typeof(Cronus.ProjectionsBooter), typeof(Cronus.ProjectionsBooter), ServiceLifetime.Transient));

            yield return(new DiscoveredModel(typeof(BoundedContext), typeof(BoundedContext), ServiceLifetime.Transient));

            var loadedTypes = context.Assemblies.Find <IEvent>().Where(type => type != typeof(EntityEvent));

            yield return(new DiscoveredModel(typeof(TypeContainer <IEvent>), new TypeContainer <IEvent>(loadedTypes)));
        }
コード例 #11
0
        protected virtual IEnumerable <DiscoveredModel> DiscoverAggregateRepository(DiscoveryContext context)
        {
            yield return(new DiscoveredModel(typeof(AggregateRepository), typeof(AggregateRepository), ServiceLifetime.Transient));

            if ("true".Equals(context.Configuration["Cronus:PublishAggregateCommits"], System.StringComparison.OrdinalIgnoreCase))
            {
                yield return(new DiscoveredModel(typeof(AggregateCommitPublisherRepository), provider => new AggregateCommitPublisherRepository(provider.GetRequiredService <AggregateRepository>(), provider.GetRequiredService <IPublisher <AggregateCommit> >(), provider.GetRequiredService <CronusContext>(), provider.GetService <ILogger <AggregateCommitPublisherRepository> >()), ServiceLifetime.Transient));

                yield return(new DiscoveredModel(typeof(CronusAggregateRepository), provider => new CronusAggregateRepository(provider.GetRequiredService <AggregateCommitPublisherRepository>(), provider.GetRequiredService <IPublisher <IEvent> >(), provider.GetRequiredService <IPublisher <IPublicEvent> >(), provider.GetRequiredService <CronusContext>()), ServiceLifetime.Transient));
            }
            else
            {
                yield return(new DiscoveredModel(typeof(CronusAggregateRepository), provider => new CronusAggregateRepository(provider.GetRequiredService <AggregateRepository>(), provider.GetRequiredService <IPublisher <IEvent> >(), provider.GetRequiredService <IPublisher <IPublicEvent> >(), provider.GetRequiredService <CronusContext>()), ServiceLifetime.Transient));
            }

            yield return(new DiscoveredModel(typeof(LoggingAggregateRepository), provider => new LoggingAggregateRepository(provider.GetRequiredService <CronusAggregateRepository>(), provider.GetService <ILogger <LoggingAggregateRepository> >()), ServiceLifetime.Transient));

            yield return(new DiscoveredModel(typeof(IAggregateRepository), provider => provider.GetRequiredService <LoggingAggregateRepository>(), ServiceLifetime.Transient));
        }
コード例 #12
0
ファイル: DiscoveryScanner.cs プロジェクト: Elders/Cronus
        public IEnumerable <IDiscoveryResult <object> > Scan(DiscoveryContext context)
        {
            List <Type> allTypes = context.Assemblies
                                   .SelectMany(asm => asm
                                               .GetLoadableTypes()
                                               .Where(type => type.IsAbstract == false && type.IsClass && typeof(IDiscovery <object>).IsAssignableFrom(type)))
                                   .ToList();

            IEnumerable <IDiscovery <object> > discoveries = allTypes
                                                             .Where(candidate => allTypes.Where(t => t.BaseType == candidate).Any() == false) // filter out discoveries which inherit from each other. We remove the base discoveries
                                                             .Select(dt => (IDiscovery <object>)FastActivator.CreateInstance(dt));

            foreach (var discovery in discoveries)
            {
                logger.Info(() => $"Discovered {discovery.Name}");

                yield return(discovery.Discover(context));
            }
        }
コード例 #13
0
        protected virtual IEnumerable <DiscoveredModel> DiscoverIndices(DiscoveryContext context)
        {
            var appIndices = context.Assemblies.Find <IEventStoreIndex>();

            yield return(new DiscoveredModel(typeof(TypeContainer <IEventStoreIndex>), new TypeContainer <IEventStoreIndex>(appIndices)));

            foreach (var indexDef in appIndices)
            {
                yield return(new DiscoveredModel(indexDef, indexDef, ServiceLifetime.Scoped));
            }

            var systemIndices = context.Assemblies.Find <ICronusEventStoreIndex>();

            yield return(new DiscoveredModel(typeof(TypeContainer <ICronusEventStoreIndex>), new TypeContainer <ICronusEventStoreIndex>(systemIndices)));

            foreach (var indexDef in systemIndices)
            {
                yield return(new DiscoveredModel(indexDef, indexDef, ServiceLifetime.Scoped));
            }
        }
コード例 #14
0
ファイル: DiscoveryScanner.cs プロジェクト: randyammar/Cronus
        protected override DiscoveryResult <DiscoveryScanner> DiscoverFromAssemblies(DiscoveryContext context)
        {
            var discoveries = context.Assemblies
                              .SelectMany(asm => asm
                                          .GetLoadableTypes()
                                          .Where(type => type.IsAbstract == false && type.IsClass && typeof(IDiscovery <object>).IsAssignableFrom(type) && type != typeof(DiscoveryScanner)))
                              .Select(dt => (IDiscovery <object>)FastActivator.CreateInstance(dt));

            foreach (var discovery in discoveries)
            {
                log.Info($"Discovered {discovery.Name}");

                discovery.AssignPropertySafely <IHaveConfiguration>(x => x.Configuration = context.Configuration);

                var discoveryResult = discovery.Discover();
                cronusServicesProvider.HandleDiscoveredModel(discoveryResult);
            }

            return(new DiscoveryResult <DiscoveryScanner>());
        }
コード例 #15
0
        protected virtual IEnumerable <DiscoveredModel> DiscoverMigrations(DiscoveryContext context)
        {
            IEnumerable <Type> loadedMigrations = context.Assemblies.Find <IMigration>();

            foreach (var migrationType in loadedMigrations)
            {
                var directInterfaces = GetDirectInterfaces(migrationType);

                foreach (var interfaceBase in directInterfaces)
                {
                    var generics = interfaceBase.GetGenericArguments();
                    if (generics.Length == 1 && typeof(IMigration).IsAssignableFrom(interfaceBase))
                    {
                        var tenantResolverType        = typeof(IMigration <>);
                        var tenantResolverTypeGeneric = tenantResolverType.MakeGenericType(generics.Single());
                        yield return(new DiscoveredModel(tenantResolverTypeGeneric, migrationType, ServiceLifetime.Transient)
                        {
                            CanAddMultiple = true
                        });
                    }
                }
            }
コード例 #16
0
 protected virtual IEnumerable <DiscoveredModel> DiscoverWorkflows(DiscoveryContext context)
 {
     return(DiscoverModel <Workflow <HandleContext>, MessageHandleWorkflow>(ServiceLifetime.Transient));
 }
コード例 #17
0
 protected override DiscoveryResult <IWorkflow> DiscoverFromAssemblies(DiscoveryContext context)
 {
     return(new DiscoveryResult <IWorkflow>(DiscoverWorkflows(context), RegisterGG));
 }
コード例 #18
0
 protected override DiscoveryResult <MigrationDiscovery> DiscoverFromAssemblies(DiscoveryContext context)
 {
     return(new DiscoveryResult <MigrationDiscovery>(GetModels(context)));
 }
コード例 #19
0
 IEnumerable <DiscoveredModel> GetModels(DiscoveryContext context)
 {
     yield return(new DiscoveredModel(typeof(CopyEventStore <,>), typeof(CopyEventStore <,>), ServiceLifetime.Transient));
 }
コード例 #20
0
 protected override DiscoveryResult <IWorkflow> DiscoverFromAssemblies(DiscoveryContext context)
 {
     return(new DiscoveryResult <IWorkflow>(GetModels()));
 }
コード例 #21
0
 protected override DiscoveryResult <ProjectionPlayer> DiscoverFromAssemblies(DiscoveryContext context)
 {
     return(new DiscoveryResult <ProjectionPlayer>(GetModels()));
 }
コード例 #22
0
        protected override DiscoveryResult <IAggregateRepository> DiscoverFromAssemblies(DiscoveryContext context)
        {
            IEnumerable <DiscoveredModel> models =
                DiscoverEventStreamIntegrityPolicy <EventStreamIntegrityPolicy>(context)
                .Concat(DiscoverAggregateRepository(context));

            return(new DiscoveryResult <IAggregateRepository>(models));
        }
コード例 #23
0
 protected override DiscoveryResult <ITenantList> DiscoverFromAssemblies(DiscoveryContext context)
 {
     return(new DiscoveryResult <ITenantList>(GetModels()));
 }
コード例 #24
0
 protected override DiscoveryResult <IPublisher <IMessage> > DiscoverFromAssemblies(DiscoveryContext context)
 {
     return(new DiscoveryResult <IPublisher <IMessage> >(GetModels()));
 }
コード例 #25
0
 protected virtual IEnumerable <DiscoveredModel> DiscoverEventStreamIntegrityPolicy <TIntegrityPolicy>(DiscoveryContext context) where TIntegrityPolicy : IIntegrityPolicy <EventStream>
 {
     return(DiscoverModel <IIntegrityPolicy <EventStream>, TIntegrityPolicy>(ServiceLifetime.Transient));
 }
コード例 #26
0
 protected override DiscoveryResult <IEventStore> DiscoverFromAssemblies(DiscoveryContext context)
 {
     return(new DiscoveryResult <IEventStore>(GetModels(context)));
 }
コード例 #27
0
 protected override DiscoveryResult <ICronusHost> DiscoverFromAssemblies(DiscoveryContext context)
 {
     return(new DiscoveryResult <ICronusHost>(GetModels(context)));
 }
コード例 #28
0
ファイル: DiscoveryBase.cs プロジェクト: Elders/Cronus
 public IDiscoveryResult <TCronusService> Discover(DiscoveryContext context)
 {
     return(DiscoverFromAssemblies(context));
 }
コード例 #29
0
ファイル: DiscoveryBase.cs プロジェクト: Elders/Cronus
 protected abstract DiscoveryResult <TCronusService> DiscoverFromAssemblies(DiscoveryContext context);
コード例 #30
0
 protected override DiscoveryResult <IAggregateRepository> DiscoverFromAssemblies(DiscoveryContext context)
 {
     return(new DiscoveryResult <IAggregateRepository>(GetModels()));
 }