/// <summary> /// Adds a <see cref="IStartupModule"/> by the specified type. /// The type will be activated using the default, parameterless constructor. /// </summary> /// <param name="type">The type of the <see cref="IStartupModule"/>.</param> public void AddStartupModule(Type type) { if (typeof(IStartupModule).IsAssignableFrom(type)) { var instance = Activate(type); StartupModules.Add(instance); } else { throw new ArgumentException( $"Specified startup module '{type.Name}' does not implement {nameof(IStartupModule)}.", nameof(type)); } }
/// <summary> /// Discovers <see cref="IStartupModule"/> implementations from the specified assemblies. /// </summary> public void DiscoverStartupModules(params Assembly[] assemblies) { if (assemblies == null || assemblies.Length == 0 || assemblies.All(a => a == null)) { throw new ArgumentException("No assemblies to discover startup modules from specified.", nameof(assemblies)); } foreach (var type in assemblies.SelectMany(a => a.ExportedTypes)) { if (typeof(IStartupModule).IsAssignableFrom(type)) { var instance = Activate(type); StartupModules.Add(instance); } else if (typeof(IApplicationInitializer).IsAssignableFrom(type)) { ApplicationInitializers.Add(type); } } }
/// <summary> /// Adds an inline middleware configuration to the application. /// </summary> /// <param name="action">A callback to configure the middleware pipeline.</param> public void ConfigureMiddleware(Action <IApplicationBuilder, ConfigureMiddlewareContext> action) => StartupModules.Add(new InlineMiddlewareConfiguration(action));
/// <summary> /// Adds the <see cref="IStartupModule"/> instance of type <typeparamref name="T"/>. /// </summary> /// <typeparam name="T">The type of the <see cref="IStartupModule"/>.</typeparam> /// <param name="startupModule">The <see cref="IStartupModule"/> instance.</param> public void AddStartupModule <T>(T startupModule) where T : IStartupModule => StartupModules.Add(startupModule);