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 void Configure(IApplicationBuilder app) | |
{ | |
app.UseAuthentication(); | |
app.UseMyMiddleware(Configuration); | |
app.UseMvc(); | |
} |
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
// AddMvcCore devuelve un objeto IMvcCoreBuilder que permite usar una | |
// interfaz fluida para configurar Mvc | |
services.AddMvcCore() | |
.AddAuthorization() | |
.AddJsonFormatters(); | |
// El método AddIdentityServerAuthentication acepta un parámetro Action | |
// donde especificamos una expresión lambda que usa propiedades | |
// expuestas en el objeto options | |
services.AddAuthentication("Bearer") |
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 void ConfigureServices(IServiceCollection services) | |
{ | |
// Se crea una nueva instacia cada vez que se solicita | |
services.AddTransient<IOperationTransient, Operation>(); | |
// Se crea una nueva instacia por petición HTTP | |
services.AddScoped<IOperationScoped, Operation>(); | |
// Se crea una única instancia para toda la aplicación | |
services.AddSingleton<IOperationSingleton, Operation>(); |
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
// Si hemos usado CreateDefaultBuilder en la configuración del Host | |
// tendremos la opción de recibirla por inyección en el constructor | |
public Startup(IHostingEnvironment env, IConfiguration configuration) | |
{ | |
HostingEnvironment = env; | |
Configuration = configuration; | |
} | |
// Si no hemos usado CreateDefaultBuilder en la configuración del Host | |
// deberemos registrar la configuración en el 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 Startup(IHostingEnvironment env, IMyClass myClass) | |
{ | |
HostingEnvironment = env; | |
MyClass = myClass; | |
} |
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 IWebHost BuildWebHost(string[] args) => | |
WebHost.CreateDefaultBuilder(args) | |
.ConfigureServices(services => | |
services.AddScoped<IMyClass, MyClass>() | |
.UseStartup<Startup>() | |
.Build(); |
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) | |
{ | |
BuildWebHost(args).Run(); | |
} | |
public static IWebHost BuildWebHost(string[] args) => | |
WebHost.CreateDefaultBuilder(args) | |
.UseStartup<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 Task Main(); | |
public static Task<int> Main(); | |
public static Task Main(string[] args); | |
public static Task<int> Main(string[] args); |
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
static async Task Main(string[] args) | |
{ | |
using (var reader = File.OpenText("MyFile.txt")) | |
{ | |
var fileText = await reader.ReadToEndAsync(); | |
} | |
} |
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 void Main(); | |
public static int Main(); | |
public static void Main(string[] args); | |
public static int Main(string[] args); |