Mi pregunta es para entender el código cuando se crea un proyecto ASP Net Core. Hay dos clases, Program y Startup (creadas por defecto).
El main llama al siguiente metodo:
public static IWebHost BuildWebHost(string[] args) =>
WebHost.CreateDefaultBuilder(args)
.UseStartup<Startup>()
.Build();
Donde según entiendo envías la otra clase ya existente (Startup).
public class Startup
{
public Startup(IHostingEnvironment env)
{
var builder = new ConfigurationBuilder()
.SetBasePath(env.ContentRootPath)
.AddJsonFile("appsettings.json", optional: true, reloadOnChange: true)
.AddJsonFile($"appsettings.{env.EnvironmentName}.json", optional: true);
builder.AddEnvironmentVariables();
Configuration = builder.Build();
//Configuration = configuration;
}
public IConfiguration Configuration { get; }
// This method gets called by the runtime. Use this method to add services to the container.
public void ConfigureServices(IServiceCollection services)
{
services.AddMvc();
services.AddSingleton<IUnitOfWork>(
(options) => new CibertecUnitOfWork(Configuration.GetConnectionString("CibertecConnection"))
);
services.AddTransient<IProductoLogica, ProductoLogica>();
}
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
public void Configure(IApplicationBuilder app, IHostingEnvironment env)
{
if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
}
app.UseMvc();
}
}
Ahora mi pregunta es como es que del otro lado, se puede usar esta clase Startup enviada dado que como verán no tienen un padre en común o interfaz.
Espero puedan ayudarme, no me deja dormir el no saber como se hace eso.