protected void InitializeRCommon(IServiceCollection services) { base.InitializeBootstrapper(services); //services.AddDbContext<RCommonDbContext, TestDbContext>(); //services.AddDbContext<RCommonDbContext, TestDbContext>(ServiceLifetime.Transient); ConfigureRCommon.Using(new DotNetCoreContainerAdapter(services)) .WithStateStorage <DefaultStateStorageConfiguration>() .WithExceptionHandling <EhabExceptionHandlingConfiguration>(x => x.UsingDefaultExceptionPolicies()) .WithUnitOfWork <DefaultUnitOfWorkConfiguration>() .WithObjectAccess <EFCoreConfiguration>( x => x.UsingDbContext <TestDbContext>()) .And <CommonApplicationServicesConfiguration>(); this.ServiceProvider = services.BuildServiceProvider(); this.Logger = this.ServiceProvider.GetService <ILogger>(); Debug.WriteLine($"Total Services Registered: {services.Count}"); foreach (var service in services) { Debug.WriteLine($"Service: {service.ServiceType.FullName}\n Lifetime: {service.Lifetime}\n Instance: {service.ImplementationType?.FullName}"); } }
protected void InitializeRCommon(IServiceCollection services) { ConfigureRCommon.Using(new DotNetCoreContainerAdapter(services)) .And <CommonApplicationServicesConfiguration>(); this.ServiceProvider = services.BuildServiceProvider(); this.Logger = this.ServiceProvider.GetService <ILogger>(); Debug.WriteLine($"Total Services Registered: {services.Count}"); foreach (var service in services) { Debug.WriteLine($"Service: {service.ServiceType.FullName}\n Lifetime: {service.Lifetime}\n Instance: {service.ImplementationType?.FullName}"); } this.InitializeBootstrapper(services); }
protected void InitializeRCommon(IServiceCollection services) { base.InitializeBootstrapper(services); ConfigureRCommon.Using(new DotNetCoreContainerAdapter(services)) .WithExceptionHandling <EhabExceptionHandlingConfiguration>(x => x.UsingDefaultExceptionPolicies()); this.ServiceProvider = services.BuildServiceProvider(); this.Logger = this.ServiceProvider.GetService <ILogger>(); Debug.WriteLine($"Total Services Registered: {services.Count}"); foreach (var service in services) { Debug.WriteLine($"Service: {service.ServiceType.FullName}\n Lifetime: {service.Lifetime}\n Instance: {service.ImplementationType?.FullName}"); } }
static void Main(string[] args) { var config = new ConfigurationBuilder() .AddJsonFile("appsettings.json", optional: true, reloadOnChange: true); Configuration = config.Build(); var services = new ServiceCollection(); services.AddSingleton <ILogger>(TestLogger.Create()); services.AddSingleton <IConfiguration>(Configuration); services.AddLogging(x => x.AddConsole().SetMinimumLevel(LogLevel.Trace)); ConfigureRCommon.Using(new DotNetCoreContainerAdapter(services)) .WithStateStorage <DefaultStateStorageConfiguration>() .WithUnitOfWork <DefaultUnitOfWorkConfiguration>() .WithObjectAccess <EFCoreConfiguration>(x => { // Add all the DbContexts here x.UsingDbContext <TestDbContext>(); }) .WithExceptionHandling <EhabExceptionHandlingConfiguration>(x => x.UsingDefaultExceptionPolicies()) .And <CommonApplicationServicesConfiguration>() .And <SampleAppConfiguration>(); // Mapping Profiles services.AddAutoMapper(x => { x.AddProfile <MappingProfile>(); }); _serviceProvider = services.BuildServiceProvider(); // Add Local Services Start(); Console.ReadLine(); }
// ConfigureServices is where you register dependencies. This gets // called by the runtime before the ConfigureContainer method, below. public void ConfigureServices(IServiceCollection services) { // Add services to the collection. Don't build or return // any IServiceProvider or the ConfigureContainer method // won't get called. // Configure RCommon ConfigureRCommon.Using(new DotNetCoreContainerAdapter(services)) // Allows us to use generic Dependency Injection. We could easily swap out for Autofac with a few lines of code .WithStateStorage <DefaultStateStorageConfiguration>() // Basic state management. This layer mostly encapsulates the web runtime. Microsoft has a bad habit of revising what an HttpContext is/means so we limit that impact. .WithUnitOfWork <DefaultUnitOfWorkConfiguration>() // Everything releated to transaction management. Powerful stuff happens here. .WithObjectAccess <EFCoreConfiguration>(x => // Repository/ORM configuration. We could easily swap out to NHibernate without impact to domain service up through the stack { // Add all the DbContexts here x.UsingDbContext <SamplesContext>(); }) .WithExceptionHandling <EhabExceptionHandlingConfiguration>(x => // I prefer using Enterprise Library for this. It is one of the only fully though through libraries for exception handling. x.UsingDefaultExceptionPolicies()) .And <CommonApplicationServicesConfiguration>() .And <DomainLayerConfiguration>() .And <ApplicationLayerConfiguration>(); // AutoMapper Mapping Profiles services.AddAutoMapper(x => // Where all of our DTO mapping occurs { x.AddProfile <ApplicationLayerMappingProfile>(); }); services.AddOptions(); ConfigureCookieSettings(services); /*services.AddIdentity<ApplicationUser, IdentityRole>() * .AddDefaultUI() * .AddEntityFrameworkStores<ApplicationDbContext>() * .AddDefaultTokenProviders() * .AddRoleManager<RoleManager<IdentityRole>>();*/ services.AddDbContext <ApplicationDbContext>(options => options.UseSqlServer( Configuration.GetConnectionString("Samples"))); services.AddDefaultIdentity <IdentityUser>(options => options.SignIn.RequireConfirmedAccount = true) .AddEntityFrameworkStores <ApplicationDbContext>(); services.AddControllersWithViews(); services.AddRazorPages(); services.AddMvc(options => { // If we wanted caching we could use this /*options.CacheProfiles.Add("Default0", new CacheProfile() * { * NoStore = true, * Location = ResponseCacheLocation.None, * Duration = 0 * });*/ }) .SetCompatibilityVersion(Microsoft.AspNetCore.Mvc.CompatibilityVersion.Latest) .AddSessionStateTempDataProvider(); services.AddSession(); services.AddRazorPages(options => { options.Conventions.AuthorizeFolder("/admin"); }).AddRazorRuntimeCompilation(); services.AddControllersWithViews(); services.AddHttpContextAccessor(); // Allows us to encapsulate the HttpContext in RCommon }