示例#1
0
 /// <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));
     }
 }
示例#2
0
        /// <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);
                }
            }
        }
示例#3
0
 /// <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));
示例#4
0
 /// <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);