public IEnumerable <ComponentDescriptor> Create() { var types = ComponentTypeProvider.GetAll(); MissingComponentAttributeChecker.Check(types); MultipleComponentsInSingleAssemblyChecker.Check(types); DuplicateComponentIdChecker.Check(types); var result = new List <ComponentDescriptor>(); foreach (var type in types) { var componentId = type.GetCustomAttribute <ComponentAttribute>().Id; result.Add(new ComponentDescriptor(componentId, new AssemblyWrapper(type.Assembly))); } foreach (var assembly in ComponentAssemblyProvider.GetAll()) { if (result.Any(c => c.Assembly.Equals(assembly))) { continue; } result.Add(new ComponentDescriptor(assembly.GetName().Name, new AssemblyWrapper(assembly))); } if (Logger.IsEnabled(LogLevel.Information)) { Logger.LogInformation($"Detected {result.Count} components: {string.Join(", ", result.Select(r => r.Id))}"); } return(result); }
public static void AddCloudy(this IServiceCollection services, Action <CloudyConfigurator> configure) { services.Configure <RouteOptions>(options => { options.ConstraintMap.Add("contentroute", typeof(ContentRouteConstraint)); }); var options = new CloudyOptions(); var configurator = new CloudyConfigurator(services, options); configure(configurator); configurator.AddComponent <CloudyComponent>(); if (Assembly.GetCallingAssembly() != Assembly.GetExecutingAssembly()) { configurator.AddComponentAssembly(Assembly.GetCallingAssembly()); } if (!options.HasDocumentProvider) { configurator.WithInMemoryDatabase(); } var componentAssemblyProvider = new ComponentAssemblyProvider(options.ComponentAssemblies); services.AddSingleton <IComponentAssemblyProvider>(componentAssemblyProvider); var componentTypeProvider = new ComponentTypeProvider(options.Components); services.AddSingleton <IComponentTypeProvider>(componentTypeProvider); new CloudyDependencyInjector().InjectDependencies(services); foreach (var injector in new DependencyInjectorProvider(new DependencyInjectorCreator(componentAssemblyProvider, componentTypeProvider)).GetAll()) { injector.InjectDependencies(services); } services.AddTransient <IStartupFilter, InitializerBootstrapper>(); }
public IEnumerable <IDependencyInjector> Create() { var result = new List <IDependencyInjector>(); foreach (var type in ComponentAssemblyProvider.GetAll().SelectMany(a => a.GetTypes())) { if (!typeof(IDependencyInjector).IsAssignableFrom(type)) { continue; } if (type.IsAbstract || type.IsInterface) { continue; } result.Add((IDependencyInjector)Activator.CreateInstance(type)); } foreach (var type in ComponentTypeProvider.GetAll().SelectMany(t => t.Assembly.GetTypes())) { if (!typeof(IDependencyInjector).IsAssignableFrom(type)) { continue; } if (type.IsAbstract || type.IsInterface) { continue; } result.Add((IDependencyInjector)Activator.CreateInstance(type)); } return(result); }