Пример #1
0
        public static IServiceCollection Add_doLittle(this IServiceCollection services)
        {
            var logAppenders = LoggingConfigurator.DiscoverAndConfigure(Internals.LoggerFactory);

            doLittle.Logging.ILogger logger = new Logger(logAppenders);

            var assembliesConfigurationBuilder = new AssembliesConfigurationBuilder();

            assembliesConfigurationBuilder.IncludeAll();

            var contractToImplementorsMap = new ContractToImplementorsMap();
            var executingAssembly         = typeof(doLittleModule).GetTypeInfo().Assembly;

            contractToImplementorsMap.Feed(executingAssembly.GetTypes());

            var assemblySpecifiers = new AssemblySpecifiers(assembliesConfigurationBuilder.RuleBuilder, logger);

            assemblySpecifiers.SpecifyUsingSpecifiersFrom(executingAssembly);

            var assembliesConfiguration = new AssembliesConfiguration(assembliesConfigurationBuilder.RuleBuilder);
            var assemblyFilters         = new AssemblyFilters(assembliesConfiguration);
            var assemblyProvider        = new AssemblyProvider(
                new ICanProvideAssemblies[] { new DefaultAssemblyProvider(logger) },
                assemblyFilters,
                new AssemblyUtility(),
                assemblySpecifiers);

            Internals.AllAssemblies           = assemblyProvider.GetAll();
            Internals.AssemblyFilters         = assemblyFilters;
            Internals.AssembliesConfiguration = assembliesConfiguration;
            Internals.AssemblyProvider        = assemblyProvider;
            Internals.Assemblies = new Assemblies(assemblyProvider);

            return(services);
        }
Пример #2
0
        protected override void Load(ContainerBuilder builder)
        {
            var selfBindingRegistrationSource = new AnyConcreteTypeNotAlreadyRegisteredSource(type =>
                                                                                              !type.Namespace.StartsWith("Microsoft") &&
                                                                                              !type.Namespace.StartsWith("System"));

            var logAppenders = LoggingConfigurator.DiscoverAndConfigure(Internals.LoggerFactory);

            doLittle.Logging.ILogger logger = new Logger(logAppenders);
            builder.RegisterType <Logger>().As <doLittle.Logging.ILogger>().SingleInstance();

            builder.RegisterType <ControllerActionCommandContextManager>().As <ICommandContextManager>().SingleInstance();

            builder.RegisterGeneric(typeof(InstancesOf <>)).As(typeof(IInstancesOf <>));
            builder.RegisterGeneric(typeof(ImplementationsOf <>)).As(typeof(IImplementationsOf <>));
            builder.RegisterGeneric(typeof(AggregateRootRepositoryFor <>)).As(typeof(IAggregateRootRepositoryFor <>));

            builder.RegisterInstance(Internals.AssemblyFilters).As <IAssemblyFilters>();
            builder.RegisterInstance(Internals.AssembliesConfiguration).As <AssembliesConfiguration>();
            builder.RegisterInstance(Internals.AssemblyProvider).As <IAssemblyProvider>();
            builder.RegisterInstance(Internals.Assemblies).As <IAssemblies>();

            builder.RegisterType <ConvertersProvider>().AsSelf();

            //Internals.Assemblies.GetAll().ForEach(assembly => builder.RegisterAssemblyTypes(assembly).AsSelf().AsImplementedInterfaces());

            builder.RegisterType <Container>().As <doLittle.DependencyInversion.IContainer>().SingleInstance();
            builder.RegisterType <UncommittedEventStreamCoordinator>().As <IUncommittedEventStreamCoordinator>()
            .SingleInstance();
            builder.RegisterType <Infrastructure.AspNet.EventProcessors>().As <IEventProcessors>().SingleInstance();
            builder.RegisterType <NullEventProcessorLog>().As <IEventProcessorLog>().SingleInstance();
            builder.RegisterType <NullEventProcessorStates>().As <IEventProcessorStates>().SingleInstance();
            builder.RegisterType <NullEventStore>().As <IEventStore>().SingleInstance();
            builder.RegisterType <NullEventSourceVersions>().As <IEventSourceVersions>().SingleInstance();
            builder.RegisterType <NullEventSequenceNumbers>().As <IEventSequenceNumbers>().SingleInstance();

            builder.RegisterType <CommittedEventStreamSender>().As <ICanSendCommittedEventStream>().SingleInstance();
            builder.RegisterType <CommittedEventStreamReceiver>().As <ICanReceiveCommittedEventStream>().SingleInstance();
            builder.RegisterType <CommittedEventStreamBridge>().As <ICommittedEventStreamBridge>().SingleInstance();
            builder.RegisterType <CommittedEventStreamCoordinator>().As <ICommittedEventStreamCoordinator>().SingleInstance();
            builder.RegisterType <ProcessMethodEventProcessors>().AsSelf().SingleInstance();

            var applicationStructureBuilder =
                new ApplicationStructureConfigurationBuilder()
                .Include(ApplicationAreas.Domain, "Infrastructure.AspNet.-{BoundedContext}.-{Module}.-{Feature}.^{SubFeature}*")
                .Include(ApplicationAreas.Domain, "Infrastructure.Kafka.BoundedContexts.-{BoundedContext}.-{Module}.-{Feature}.^{SubFeature}*")
                .Include(ApplicationAreas.Domain, "Domain.-{BoundedContext}.-{Module}.-{Feature}.^{SubFeature}*")
                .Include(ApplicationAreas.Events, "Events.-{BoundedContext}.-{Module}.-{Feature}.^{SubFeature}*")
                .Include(ApplicationAreas.Read, "Read.-{BoundedContext}.-{Module}.-{Feature}.^{SubFeature}*");

            var applicationStructure = applicationStructureBuilder.Build();
            var applicationName      = (ApplicationName)"CBS";
            var application          = new Application(applicationName, applicationStructure);

            builder.Register(_ => application).As <IApplication>().SingleInstance();
            builder.Register(_ => Internals.BoundedContext).AsSelf();

            var identity = new ClaimsIdentity();

            identity.AddClaim(new Claim(identity.NameClaimType, "[Anonymous]"));
            var principal = new ClaimsPrincipal(identity);

            var tenant = new Tenant("IFRC");

            builder.RegisterInstance(tenant).As <ITenant>();

            builder.Register(_ =>
                             new doLittle.Runtime.Execution.ExecutionContext(
                                 principal,
                                 CultureInfo.InvariantCulture,
                                 (context, details) => { },
                                 application,
                                 tenant)
                             ).As <IExecutionContext>();

            builder.RegisterSource(new EventProcessorRegistrationSource());
        }
Пример #3
0
        /// <summary>
        /// Configure by letting Bifrost discover anything that implements the discoverable configuration interfaces
        /// </summary>
        /// <returns></returns>
        public static Configure DiscoverAndConfigure(
#if (!NET461)
            ILoggerFactory loggerFactory,
#endif
            Action <AssembliesConfigurationBuilder> assembliesConfigurationBuilderCallback = null,
            IEnumerable <ICanProvideAssemblies> additionalAssemblyProviders = null)
        {
#if (NET461)
            var logAppenders = LoggingConfigurator.DiscoverAndConfigure();
#else
            var logAppenders = LoggingConfigurator.DiscoverAndConfigure(loggerFactory);
#endif
            Logging.ILogger logger = new Logger(logAppenders);
            logger.Information("Starting up");

            IContractToImplementorsMap contractToImplementorsMap;


            var assembliesConfigurationBuilder = BuildAssembliesConfigurationIfCallbackDefined(assembliesConfigurationBuilderCallback);

            logger.Trace("Settings up contract to implementors map");

            contractToImplementorsMap = new ContractToImplementorsMap();
            var executingAssembly = typeof(Configure).GetTypeInfo().Assembly;
            contractToImplementorsMap.Feed(executingAssembly.GetTypes());

            logger.Trace("Specifying which assemblies to include");
            var assemblySpecifiers = new AssemblySpecifiers(contractToImplementorsMap, new TypeFinder(), assembliesConfigurationBuilder.RuleBuilder);
            assemblySpecifiers.SpecifyUsingSpecifiersFrom(executingAssembly);

            var assemblyProviders = new List <ICanProvideAssemblies>
            {
#if (NET461)
                new AppDomainAssemblyProvider(logger),
#else
                new DefaultAssemblyProvider(logger),
#endif
                new FileSystemAssemblyProvider(new FileSystem(), logger)
            };


            if (additionalAssemblyProviders != null)
            {
                assemblyProviders.AddRange(additionalAssemblyProviders);
            }

            var assembliesConfiguration = new AssembliesConfiguration(assembliesConfigurationBuilder.RuleBuilder);
            var assemblyProvider        = new AssemblyProvider(
                assemblyProviders,
                new AssemblyFilters(assembliesConfiguration),
                new AssemblyUtility(),
                assemblySpecifiers,
                contractToImplementorsMap,
                logger);

            var assemblies = assemblyProvider.GetAll();

            var canCreateContainerType = DiscoverCanCreateContainerType(assemblies);
            ThrowIfCanCreateContainerNotFound(canCreateContainerType);
            ThrowIfCanCreateContainerDoesNotHaveDefaultConstructor(canCreateContainerType);
            var canCreateContainerInstance = Activator.CreateInstance(canCreateContainerType) as ICanCreateContainer;
            var container = canCreateContainerInstance.CreateContainer();

            container.Bind(logAppenders);
            container.Bind(logger);

            var configure = With(
                container,
                assembliesConfiguration,
                assemblyProvider,
                contractToImplementorsMap);
            configure.EntryAssembly = canCreateContainerType.GetTypeInfo().Assembly;
            configure.Initialize();
            return(configure);
        }