public void GetStartupTypes_WithType() { var actualTypes = FunctionsStartupAttribute.GetStartupTypes(typeof(FunctionsStartupAttributeTest).Assembly, typeof(TargetTypeWithAttribute)); // Ordering is based on the Order properties var expectedTypes = new[] { typeof(TestStartup2), typeof(TestStartup3), typeof(TestStartup1) }; Assert.Equal(expectedTypes, actualTypes); }
public void GetStartupTypes_NoType() { var actualTypes = FunctionsStartupAttribute.GetStartupTypes(typeof(FunctionsStartupAttributeTest).Assembly, null); // TestStartup2 comes before TestStartup1 due to the Order properties. var expectedTypes = new[] { typeof(TestStartup2), typeof(TestStartup1) }; Assert.Equal(expectedTypes, actualTypes); }
/// <summary> /// Uses the functions startup classes specified by <see cref="FunctionsStartupAttribute"/> when configuring the host. /// Startup classes can contribute to logging, configuration sources, services, and application configuration. /// </summary> /// <param name="webHostBuilder">The web host builder to configure.</param> /// <param name="assembly">The assembly to query for attributes specifying startup classes.</param> /// <param name="functionType">The function type to query for attributes specifying startup classes, or null to skip this query.</param> /// <returns>The original builder, for method chaining.</returns> public static IWebHostBuilder UseFunctionsStartups(this IWebHostBuilder webHostBuilder, Assembly assembly, Type?functionType) { foreach (var startupClass in FunctionsStartupAttribute.GetStartupTypes(assembly, functionType)) { var startup = (FunctionsStartup)Activator.CreateInstance(startupClass) !; webHostBuilder.UseFunctionsStartup(startup); } return(webHostBuilder); }