using System; | |
using System.Collections.Generic; | |
using DryIoc; | |
using DryIoc.AspNetCore.DependencyInjection; | |
using Microsoft.AspNetCore.Builder; | |
using Microsoft.AspNetCore.Hosting; | |
using Microsoft.Extensions.Configuration; | |
using Microsoft.Extensions.DependencyInjection; | |
using Microsoft.Extensions.Logging; | |
using Serilog; | |
namespace EmployeeDirectory.Api | |
{ | |
public class Startup | |
{ | |
public Startup(IHostingEnvironment env) | |
{ | |
Log.Logger = new LoggerConfiguration() | |
.MinimumLevel.Debug() | |
.Enrich.FromLogContext() | |
.WriteTo.LiterateConsole() | |
.WriteTo.RollingFile( | |
Environment.ExpandEnvironmentVariables(@"%southernroot%\logs\EmployeeDirectory.log"), | |
outputTemplate: "{Timestamp:u} [{Level}] ({CorrelationId}) {Message}{NewLine}{Exception}") | |
.CreateLogger(); | |
var builder = new ConfigurationBuilder() | |
.SetBasePath(env.ContentRootPath) | |
.AddJsonFile("appsettings.json", true, true) | |
.AddJsonFile($"appsettings.{env.EnvironmentName}.json", true) | |
.AddEnvironmentVariables(); | |
Configuration = builder.Build(); | |
} | |
public IConfigurationRoot Configuration { get; } | |
// This method gets called by the runtime. Use this method to add services to the container. | |
public IServiceProvider ConfigureServices(IServiceCollection services) | |
{ | |
// Add framework services. | |
services.AddMvc(); | |
var container = new Container().WithDependencyInjectionAdapter(services); | |
//container.Register<IRepository, Repository>(Reuse.Singleton); | |
var serviceProvider = container.Resolve<IServiceProvider>(); | |
return serviceProvider; | |
} | |
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline. | |
public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory) | |
{ | |
loggerFactory.AddConsole(Configuration.GetSection("Logging")); | |
loggerFactory.AddDebug(); | |
loggerFactory.AddSerilog(); | |
app.UseCorrelationId(); | |
app.UseMvc(); | |
} | |
internal class ServiceCollection : List<ServiceDescriptor>, IServiceCollection | |
{ | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment