コード例 #1
0
        /// <summary>
        /// Initialize assemblies setup.
        /// </summary>
        /// <param name="logger"><see cref="ILogger"/> to use for logging.</param>
        /// <param name="entryAssembly"><see cref="Assembly"/> to use as entry assembly - null indicates it will get it from the <see cref="Assembly.GetEntryAssembly()"/> method.</param>
        /// <param name="defaultAssemblyProvider">The default <see cref="ICanProvideAssemblies"/> - null inidicates it will use the default implementation.</param>
        /// <param name="excludeAllCallback">A callback to build on the exclude all specification.</param>
        /// <returns>Discovered <see cref="IAssemblies"/>.</returns>
        public static IAssemblies Start(
            ILogger logger,
            Assembly entryAssembly = null,
            ICanProvideAssemblies defaultAssemblyProvider = null,
            Action <ExcludeAll> excludeAllCallback        = null)
        {
            var assembliesConfigurationBuilder = new AssembliesConfigurationBuilder();
            var assembliesSpecification        = assembliesConfigurationBuilder
                                                 .ExcludeAll()
                                                 .ExceptProjectLibraries()
                                                 .ExceptDolittleLibraries();

            excludeAllCallback?.Invoke(assembliesSpecification);

            if (entryAssembly == null)
            {
                entryAssembly = Assembly.GetEntryAssembly();
            }

            var assembliesConfiguration = new AssembliesConfiguration(assembliesConfigurationBuilder.RuleBuilder);
            var assemblyFilters         = new AssemblyFilters(assembliesConfiguration);

            var assemblyProvider = new AssemblyProvider(
                new ICanProvideAssemblies[] { defaultAssemblyProvider ?? new DefaultAssemblyProvider(logger, entryAssembly) },
                assemblyFilters,
                new AssemblyUtility(),
                logger);

            var assemblies = new Assemblies(entryAssembly, assemblyProvider);

            return(assemblies);
        }
コード例 #2
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);
        }
コード例 #3
0
 /// <summary>
 /// Configure with a specific <see cref="IContainer"/>.
 /// </summary>
 /// <param name="container"><see cref="IContainer"/> to configure with.</param>
 /// <param name="assembliesConfiguration"><see cref="AssembliesConfiguration"/> to use.</param>
 /// <param name="assemblyProvider"><see cref="IAssemblyProvider"/> to use for providing assemblies.</param>
 /// <param name="contractToImplementorsMap"><see cref="IContractToImplementorsMap"/> for keeping track of
 /// the relationship between contracts and implementors.</param>
 /// <returns>Configuration object to continue configuration on.</returns>
 public static Configure With(
     IContainer container,
     AssembliesConfiguration assembliesConfiguration,
     IAssemblyProvider assemblyProvider,
     IContractToImplementorsMap contractToImplementorsMap)
 {
     return(With(
                container,
                new DefaultConventions(container),
                new DefaultBindings(assembliesConfiguration, assemblyProvider, contractToImplementorsMap),
                assembliesConfiguration));
 }
コード例 #4
0
ファイル: Configure.cs プロジェクト: llenroc/Bifrost
        /// <summary>
        /// Configure by letting Bifrost discover anything that implements the discoverable configuration interfaces
        /// </summary>
        /// <returns></returns>
        public static Configure DiscoverAndConfigure(Action <AssembliesConfigurationBuilder> assembliesConfigurationBuilderCallback = null, IEnumerable <ICanProvideAssemblies> additionalAssemblyProviders = null)
        {
            IContractToImplementorsMap contractToImplementorsMap;
            var assembliesConfigurationBuilder = BuildAssembliesConfigurationIfCallbackDefined(assembliesConfigurationBuilderCallback);

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

            contractToImplementorsMap.Feed(executingAssembly.GetTypes());
            var assemblySpecifiers = new AssemblySpecifiers(contractToImplementorsMap, new TypeFinder(), assembliesConfigurationBuilder.RuleBuilder);

            assemblySpecifiers.SpecifyUsingSpecifiersFrom(executingAssembly);

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


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

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

            var assemblies = assemblyProvider.GetAll();

            var canCreateContainerType = DiscoverCanCreateContainerType(assemblies);

            ThrowIfCanCreateContainerNotFound(canCreateContainerType);
            ThrowIfCanCreateContainerDoesNotHaveDefaultConstructor(canCreateContainerType);
            var canCreateContainerInstance = Activator.CreateInstance(canCreateContainerType) as ICanCreateContainer;
            var container = canCreateContainerInstance.CreateContainer();
            var configure = With(container, BindingLifecycle.Transient, assembliesConfiguration, assemblyProvider, contractToImplementorsMap);

            configure.EntryAssembly = canCreateContainerType.GetTypeInfo().Assembly;
            configure.Initialize();
            return(configure);
        }
コード例 #5
0
        Configure(
            IContainer container,
            IDefaultConventions defaultConventions,
            IDefaultBindings defaultBindings,
            AssembliesConfiguration assembliesConfiguration)
        {
            AssembliesConfiguration = assembliesConfiguration;
            container.Bind <IConfigure>(this);

            Container = container;

            defaultBindings.Initialize(Container);
            defaultConventions.Initialize();

            InitializeProperties();
        }
コード例 #6
0
        /// <summary>
        /// Configure with a specific <see cref="IContainer"/>, <see cref="IDefaultConventions"/> and <see cref="IDefaultBindings"/>
        /// </summary>
        /// <param name="container"><see cref="IContainer"/> to configure with</param>
        /// <param name="defaultConventions"><see cref="IDefaultConventions"/> to use</param>
        /// <param name="defaultBindings"><see cref="IDefaultBindings"/> to use</param>
        /// <param name="assembliesConfiguration"><see cref="AssembliesConfiguration"/> to use</param>
        /// <returns></returns>
        public static Configure With(
            IContainer container,
            IDefaultConventions defaultConventions,
            IDefaultBindings defaultBindings,
            AssembliesConfiguration assembliesConfiguration)
        {
            if (Instance == null)
            {
                lock (InstanceLock)
                {
                    Instance = new Configure(container, defaultConventions, defaultBindings, assembliesConfiguration);
                }
            }

            return(Instance);
        }
コード例 #7
0
ファイル: Configure.cs プロジェクト: llenroc/Bifrost
        Configure(IContainer container, BindingLifecycle defaultLifecycle, IDefaultConventions defaultConventions, IDefaultBindings defaultBindings, AssembliesConfiguration assembliesConfiguration)
        {
            SystemName = "[Not Set]";

            AssembliesConfiguration = assembliesConfiguration;

            container.DefaultLifecycle = defaultLifecycle;
            container.Bind <IConfigure>(this);

            Container = container;

            defaultBindings.Initialize(Container);
            defaultConventions.Initialize();

            InitializeProperties();
        }
        /// <inheritdoc/>
        public void Perform()
        {
            var assembliesConfigurationBuilder = new AssembliesConfigurationBuilder();

            assembliesConfigurationBuilder
            .ExcludeAll()
            .ExceptProjectLibraries()
            .ExceptDolittleLibraries();

            var entryAssembly = _buildTarget.Assembly;

            var assembliesConfiguration = new AssembliesConfiguration(assembliesConfigurationBuilder.RuleBuilder);
            var assemblyFilters         = new AssemblyFilters(assembliesConfiguration);

            var assemblyProvider = new Dolittle.Assemblies.AssemblyProvider(
                new ICanProvideAssemblies[] { new DefaultAssemblyProvider(_logger, entryAssembly) },
                assemblyFilters,
                new AssemblyUtility(),
                _logger
                );

            var assemblies = new Dolittle.Assemblies.Assemblies(entryAssembly, assemblyProvider);
            var contractToImplementorsMap = new ContractToImplementorsMap(new AsyncScheduler());

            Parallel.ForEach(assemblies.GetAll(), _ =>
            {
                try
                {
                    var types = _.GetTypes();
                    contractToImplementorsMap.Feed(types);
                }
                catch {}
            });

            var contractsToImplementors = contractToImplementorsMap.ContractsAndImplementors;

            var serializedMap = _serializer.SerializeMap(contractsToImplementors);

            _modifiers.AddModifier(new EmbedResource(CachedContractToImplementorsMap.MapResourceName, Encoding.UTF8.GetBytes(serializedMap)));
            var serializedTypes = _serializer.SerializeTypes(contractToImplementorsMap.All);

            _modifiers.AddModifier(new EmbedResource(CachedContractToImplementorsMap.TypesResourceName, Encoding.UTF8.GetBytes(serializedTypes)));

            var implementors = contractsToImplementors.Values.Sum(_ => _.Count());

            _buildMessages.Information($"Embedded a map with {contractsToImplementors.Keys.Count} contracts to {implementors} implementors");
        }
コード例 #9
0
        /// <summary>
        /// Configure by letting Bifrost discover anything that implements the discoverable configuration interfaces
        /// </summary>
        /// <returns></returns>
        public static Configure DiscoverAndConfigure(Action <AssembliesConfigurationBuilder> assembliesConfigurationBuilderCallback = null)
        {
            var assembliesConfigurationBuilder = BuildAssembliesConfigurationIfCallbackDefined(assembliesConfigurationBuilderCallback);
            var assembliesConfiguration        = new AssembliesConfiguration(assembliesConfigurationBuilder.RuleBuilder.Specification);

#if (SILVERLIGHT)
            var assemblyProvider = new AssemblyProvider();
#else
            var assemblyProvider = new AssemblyProvider(AppDomain.CurrentDomain, new AssemblyFilters(assembliesConfiguration));
#endif
            var assemblies = assemblyProvider.GetAll();

            var canCreateContainerType = DiscoverCanCreateContainerType(assemblies);
            ThrowIfCanCreateContainerNotFound(canCreateContainerType);
            ThrowIfCanCreateContainerDoesNotHaveDefaultConstructor(canCreateContainerType);
            var canCreateContainerInstance = Activator.CreateInstance(canCreateContainerType) as ICanCreateContainer;
            var container = canCreateContainerInstance.CreateContainer();
            var configure = With(container, BindingLifecycle.Transient, assembliesConfiguration, assemblyProvider);
            configure.EntryAssembly = canCreateContainerType.Assembly;
            configure.Initialize();
            return(configure);
        }
コード例 #10
0
 /// <summary>
 /// Initializes an instance of <see cref="AssemblyFilters"/>
 /// </summary>
 /// <param name="assembliesConfiguration"></param>
 public AssemblyFilters(AssembliesConfiguration assembliesConfiguration)
 {
     _assembliesConfiguration = assembliesConfiguration;
 }
コード例 #11
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);
        }
コード例 #12
0
 /// <summary>
 /// Configure with a specific <see cref="IContainer"/>, <see cref="IDefaultConventions"/> and <see cref="IDefaultBindings"/>
 /// </summary>
 /// <param name="container"><see cref="IContainer"/> to configure with</param>
 /// <param name="defaultConventions"><see cref="IDefaultConventions"/> to use</param>
 /// <param name="defaultBindings"><see cref="IDefaultBindings"/> to use</param>
 /// <param name="assembliesConfiguration"><see cref="AssembliesConfiguration"/> to use</param>
 /// <returns></returns>
 public static Configure With(IContainer container, IDefaultConventions defaultConventions, IDefaultBindings defaultBindings, AssembliesConfiguration assembliesConfiguration)
 {
     return(With(container, BindingLifecycle.Transient, defaultConventions, defaultBindings, assembliesConfiguration));
 }
コード例 #13
0
 /// <summary>
 /// Configure with a specific <see cref="IContainer"/>
 /// </summary>
 /// <param name="container"><see cref="IContainer"/> to configure with</param>
 /// <param name="defaultObjectLifecycle">Default <see cref="BindingLifecycle"/> for object creation/management</param>
 /// <param name="assembliesConfiguration"><see cref="AssembliesConfiguration"/> to use</param>
 /// <param name="assemblyProvider"><see cref="IAssemblyProvider"/> to use for providing assemblies</param>
 /// <returns>Configuration object to continue configuration on</returns>
 public static Configure With(IContainer container, BindingLifecycle defaultObjectLifecycle, AssembliesConfiguration assembliesConfiguration, IAssemblyProvider assemblyProvider)
 {
     return(With(container, defaultObjectLifecycle, new DefaultConventions(container), new DefaultBindings(assembliesConfiguration, assemblyProvider), assembliesConfiguration));
 }
コード例 #14
0
 /// <summary>
 /// Configure with a specific <see cref="IContainer"/> and the <see cref="BindingLifecycle">Lifecycle</see> of objects set to none
 /// </summary>
 /// <param name="container"><see cref="IContainer"/> to configure with</param>
 /// <param name="assembliesConfiguration"><see cref="AssembliesConfiguration"/> to use</param>
 /// <param name="assemblyProvider"><see cref="IAssemblyProvider"/> to use for providing assemblies</param>
 /// <returns>Configuration object to continue configuration on</returns>
 public static Configure With(IContainer container, AssembliesConfiguration assembliesConfiguration, IAssemblyProvider assemblyProvider)
 {
     return(With(container, BindingLifecycle.Transient, assembliesConfiguration, assemblyProvider));
 }
コード例 #15
0
ファイル: DefaultBindings.cs プロジェクト: csuffyy/Bifrost
 /// <summary>
 /// Initializes a new instance of <see cref="DefaultBindings"/>
 /// </summary>
 public DefaultBindings(AssembliesConfiguration assembliesConfiguration, IAssemblyProvider assemblyProvider)
 {
     _assembliesConfiguration = assembliesConfiguration;
     _assemblyProvider        = assemblyProvider;
 }
コード例 #16
0
 /// <summary>
 /// Initializes a new instance of <see cref="DefaultBindings"/>
 /// </summary>
 public DefaultBindings(AssembliesConfiguration assembliesConfiguration, IAssemblyProvider assemblyProvider, IContractToImplementorsMap contractToImplentorsMap)
 {
     _assembliesConfiguration = assembliesConfiguration;
     _assemblyProvider        = assemblyProvider;
     _contractToImplentorsMap = contractToImplentorsMap;
 }
コード例 #17
0
ファイル: Configure.cs プロジェクト: llenroc/Bifrost
 /// <summary>
 /// Configure with a specific <see cref="IContainer"/> and the <see cref="BindingLifecycle">Lifecycle</see> of objects set to none
 /// </summary>
 /// <param name="container"><see cref="IContainer"/> to configure with</param>
 /// <param name="assembliesConfiguration"><see cref="AssembliesConfiguration"/> to use</param>
 /// <param name="assemblyProvider"><see cref="IAssemblyProvider"/> to use for providing assemblies</param>
 /// <param name="contractToImplementorsMap"><see cref="IContractToImplementorsMap"/> for keeping track of the relationship between contracts and implementors</param>
 /// <returns>Configuration object to continue configuration on</returns>
 public static Configure With(IContainer container, AssembliesConfiguration assembliesConfiguration, IAssemblyProvider assemblyProvider, IContractToImplementorsMap contractToImplementorsMap)
 {
     return(With(container, BindingLifecycle.Transient, assembliesConfiguration, assemblyProvider, contractToImplementorsMap));
 }