My question is to understand the code when an ASP Net Core project is created. There are two classes, Program and Startup (created by default).
The main calls the following method:
public static IWebHost BuildWebHost(string[] args) =>
WebHost.CreateDefaultBuilder(args)
.UseStartup<Startup>()
.Build();
Where as I understand you send the other existing class (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();
}
}
Now my question is how is it that on the other side, you can use this class Startup sent since as you will see they do not have a common parent or interface.
I hope you can help me, I can not sleep because I do not know how to do that.