https://discord.umbraco.com logo
#package-development
Title
# package-development
p

p-m-j

10/14/2021, 8:16 PM
Copy code
csharp
    public static class UmbracoHost
    {
        public static IHostBuilder CreateDefaultBuilder(string[] args)
        {
            var settings = new TypeFinderSettings();

            var assembly = Assembly.GetEntryAssembly();
            var assemblyProvider = new DefaultUmbracoAssemblyProvider(
                assembly,
                NullLoggerFactory.Instance,
                settings.AdditionalEntryAssemblies
            );

            var typeFinder = new TypeFinder(NullLogger<TypeFinder>.Instance, assemblyProvider);

            // Reminder typeFinder looks only in assemblies that reference Umbraco by default so add a package ref to Umbraco.Core
            // in the lib that has your IHostingStartup implementation
            IEnumerable<string> packageHostingStartupAssemblies = typeFinder.FindClassesOfType(typeof(IHostingStartup))
                .Select(x => x.Assembly.GetName().Name!);

            var assemblies = string.Join(';', packageHostingStartupAssemblies);

            return Host.CreateDefaultBuilder(args)
                .ConfigureWebHostDefaults(web =>
                {
                    web.UseSetting(WebHostDefaults.HostingStartupAssembliesKey, assemblies);
                });
        }
    }