Last active
December 13, 2016 20:27
-
-
Save Grinderofl/4df14eda7d1abd6b73adbe1778bc4c86 to your computer and use it in GitHub Desktop.
Random way of building startup...
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static class WebHostBuilderExtensions | |
{ | |
public static WebHostBuilder UseProspero(this WebHostBuilder builder, Action<ProsperoFeatures> featuresAction) | |
{ | |
builder | |
.UseKestrel() | |
.UseContentRoot(Directory.GetCurrentDirectory()) | |
.UseIISIntegration(); | |
builder.UseConventionAutofacServiceProvider(); // Finds Module subtypes | |
var features = new ProsperoFeatures(); | |
featuresAction(features); | |
var featureInstaller = new ProsperoFeatureInstaller(features); | |
featureInstaller.Install(builder); | |
} | |
} | |
public class ProsperoFeatures | |
{ | |
public IList<Assembly> Assemblies { get; } | |
public IList<Action<IServiceCollection>> ServiceConfigurations {get;} | |
public IList<Action<SomeContainerBuilder>> ContainerBuilderActions {get;} | |
public IList<Action<IApplicationBuilder>> ApplicationBuilderActions {get;} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class Program | |
{ | |
public static void Main(string[] args) | |
{ | |
var host = new WebHostBuilder() | |
.UseProspero( | |
features => | |
features | |
.AddAssemblyContaining<CoreItem> | |
.AddAssemblyContaining<Startup> | |
.UseLogging(log => log.AddDebug()) | |
.UseImplementations(imp => imp.WithAllInterfaces()) | |
.UseAutomapper() | |
.UseServiceBus(sb => sb.WithSqlServer()) | |
.UseCoolDeveloperShit() | |
.UseBoringUserShit() | |
.UseMvc() | |
) | |
.UseStartup<Startup>() | |
.Build(); | |
host.Run(); | |
} | |
public class Startup | |
{ | |
public void ConfigureContainer(WhateverContainerWeAgreeOn container) | |
{ | |
container.RegisterMyApplicationSpecificStuff(); | |
} | |
// Alternatively | |
public void ConfigureServices(IServiceCollection services) | |
{ | |
services.AddScoped<MyService>(); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment