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); }
public IEnumerable <ISaveListener <object> > Create() { var result = new List <ISaveListener <object> >(); foreach (var type in AssemblyProvider.GetAll().SelectMany(a => a.Types)) { if (!type.IsClass) { continue; } if (type.IsAbstract) { continue; } if (!typeof(ISaveListener <object>).IsAssignableFrom(type)) { continue; } Logger.LogInformation($"Creating SaveListener {type}"); result.Add((ISaveListener <object>)Instantiator.Instantiate(type)); } return(result.AsReadOnly()); }
public IDictionary <string, IBackend> CreateAll() { var result = new Dictionary <string, IBackend>(); foreach (var assembly in AssemblyProvider.GetAll()) { foreach (var type in assembly.Types) { var attribute = type.GetCustomAttribute <DataTableBackendAttribute>(); if (attribute == null) { continue; } if (!typeof(IBackend).IsAssignableFrom(type)) { throw new DataTableBackendDoesNotImplementIBackendException(type); } result.Add(attribute.Id, (IBackend)Instantiator.Instantiate(type)); } } return(result); }
public IEnumerable <T> GetAll <T>() where T : IComposable { return(AssemblyProvider .GetAll() .SelectMany(a => a.Types) .Where(t => t.IsClass && !t.IsAbstract && !t.IsInterface && typeof(T).IsAssignableFrom(t)) .Select(t => (T)Instantiator.Instantiate(t)) .ToList() .AsReadOnly()); }
/// <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); }
/// <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); }
public IEnumerable <UIHintControlMapping> Create() { var result = new List <UIHintControlMapping>(); foreach (var assembly in AssemblyProvider.GetAll()) { foreach (var type in assembly.Types) { var controlAttribute = type.GetCustomAttribute <ControlAttribute>(); if (controlAttribute == null) { continue; } foreach (var mapControlToUIHintAttribute in type.GetCustomAttributes <MapControlToUIHintAttribute>()) { result.Add(new UIHintControlMapping(UIHintDefinitionParser.Parse(mapControlToUIHintAttribute.UIHintDefinition), controlAttribute.Id)); } } } return(result.AsReadOnly()); }
public IEnumerable <IInitializer> Create() { var result = new List <IInitializer>(); foreach (var assembly in AssemblyProvider.GetAll()) { foreach (var type in assembly.Types) { if (!typeof(IInitializer).IsAssignableFrom(type)) { continue; } if (type.IsAbstract || type.IsInterface) { continue; } result.Add((IInitializer)Instantiator.Instantiate(type)); } } return(result); }
/// <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); }