Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Removed Autofac #19

Merged
merged 1 commit into from
Jan 9, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ of starting an empty project and adding the same snippets each time, you can use

## Source code contains

1. [Autofac](https://autofac.org/)
1. ~~[Autofac]~~(https://autofac.org/) (Removed in [PR19](https://github.com/lkurzyniec/netcore-boilerplate/pull/19))
1. [Swagger](https://swagger.io/) + [Swashbuckle](https://github.com/domaindrivendev/Swashbuckle)
1. [FeatureManagement](https://github.com/microsoft/FeatureManagement-Dotnet) (Feature Flags, Feature Toggles)
1. [HealthChecks](https://github.com/Xabaril/AspNetCore.Diagnostics.HealthChecks)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
<PackageReference Include="AspNetCore.HealthChecks.MySql" Version="3.1.1" />
<PackageReference Include="AspNetCore.HealthChecks.SqlServer" Version="3.1.1" />
<PackageReference Include="AspNetCore.HealthChecks.UI.Client" Version="3.1.2" />
<PackageReference Include="Autofac.Extensions.DependencyInjection" Version="7.1.0" />
<PackageReference Include="Microsoft.CodeAnalysis.FxCopAnalyzers" Version="3.3.1">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
Expand Down

This file was deleted.

2 changes: 0 additions & 2 deletions src/HappyCode.NetCoreBoilerplate.Api/Program.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
using System;
using System.Threading.Tasks;
using Autofac.Extensions.DependencyInjection;
using HappyCode.NetCoreBoilerplate.Api.Infrastructure.Configurations;
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.Hosting;
Expand Down Expand Up @@ -34,7 +33,6 @@ public static async Task Main(string[] args)
public static IHostBuilder CreateWebHostBuilder(string[] args) =>
Host.CreateDefaultBuilder(args)
.UseSerilog()
.UseServiceProviderFactory(new AutofacServiceProviderFactory())
.ConfigureWebHostDefaults(webBuilder =>
{
webBuilder.UseStartup<Startup>();
Expand Down
13 changes: 5 additions & 8 deletions src/HappyCode.NetCoreBoilerplate.Api/Startup.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
using Autofac;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.Configuration;
Expand All @@ -13,6 +12,7 @@
using Microsoft.Extensions.Hosting;
using HappyCode.NetCoreBoilerplate.Api.Infrastructure.Registrations;
using HappyCode.NetCoreBoilerplate.Core.Settings;
using HappyCode.NetCoreBoilerplate.Core.Extensions;
using Microsoft.AspNetCore.Diagnostics.HealthChecks;
using HealthChecks.UI.Client;
using Microsoft.FeatureManagement;
Expand Down Expand Up @@ -45,8 +45,8 @@ public virtual void ConfigureServices(IServiceCollection services)
.SetCompatibilityVersion(CompatibilityVersion.Latest);

//there is a difference between AddDbContext() and AddDbContextPool(), more info https://docs.microsoft.com/en-us/ef/core/what-is-new/ef-core-2.0#dbcontext-pooling and https://stackoverflow.com/questions/48443567/adddbcontext-or-adddbcontextpool
services.AddDbContext<EmployeesContext>(options => options.UseMySql(_configuration.GetConnectionString("MySqlDb")));
services.AddDbContextPool<CarsContext>(options => options.UseSqlServer(_configuration.GetConnectionString("MsSqlDb")));
services.AddDbContext<EmployeesContext>(options => options.UseMySql(_configuration.GetConnectionString("MySqlDb")), contextLifetime: ServiceLifetime.Transient, optionsLifetime: ServiceLifetime.Singleton);
services.AddDbContextPool<CarsContext>(options => options.UseSqlServer(_configuration.GetConnectionString("MsSqlDb")), poolSize: 10);

services.Configure<ApiKeySettings>(_configuration.GetSection("ApiKey"));
services.AddSwagger(_configuration);
Expand All @@ -55,6 +55,8 @@ public virtual void ConfigureServices(IServiceCollection services)
services.AddHostedService<PingWebsiteBackgroundService>();
services.AddHttpClient(nameof(PingWebsiteBackgroundService));

services.AddCoreComponents();

services.AddFeatureManagement()
.AddFeatureFilter<TimeWindowFilter>();

Expand All @@ -63,11 +65,6 @@ public virtual void ConfigureServices(IServiceCollection services)
.AddSqlServer(_configuration.GetConnectionString("MsSqlDb"));
}

public virtual void ConfigureContainer(ContainerBuilder builder)
{
ContainerRegistration.RegisterModules(builder);
}

public virtual void Configure(IApplicationBuilder app, IWebHostEnvironment env)
{
if (env.IsDevelopment())
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
using HappyCode.NetCoreBoilerplate.Core.Repositories;
using HappyCode.NetCoreBoilerplate.Core.Services;
using Microsoft.Extensions.DependencyInjection;

namespace HappyCode.NetCoreBoilerplate.Core.Extensions
{
public static class DependencyInjectionExtensions
{
public static IServiceCollection AddCoreComponents(this IServiceCollection services)
{
services.AddTransient<IEmployeeRepository, EmployeeRepository>();
services.AddScoped<ICarService, CarService>();

return services;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Autofac" Version="6.0.0" />
<PackageReference Include="Microsoft.CodeAnalysis.Analyzers" Version="3.3.1">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using System.Net.Http;
using Autofac.Extensions.DependencyInjection;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.TestHost;
using Microsoft.Extensions.Hosting;
Expand All @@ -14,7 +13,6 @@ public class TestServerClientFixture
public TestServerClientFixture()
{
var host = new HostBuilder()
.UseServiceProviderFactory(new AutofacServiceProviderFactory())
.ConfigureWebHost(webBuilder =>
{
webBuilder
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
using Autofac;
using HappyCode.NetCoreBoilerplate.Api.Infrastructure.Filters;
using HappyCode.NetCoreBoilerplate.Api.IntegrationTests.Infrastructure.DataFeeders;
using HappyCode.NetCoreBoilerplate.Core;
using HappyCode.NetCoreBoilerplate.Core.Extensions;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Mvc;
Expand Down Expand Up @@ -31,6 +31,9 @@ public override void ConfigureServices(IServiceCollection services)
.AddDataAnnotations()
.SetCompatibilityVersion(CompatibilityVersion.Latest);

services.AddCoreComponents();
// services.AddTransient<ISomeService, SomeService>(); //if needed override registration with own test fakes

services.AddFeatureManagement();

services.AddDbContext<EmployeesContext>(options =>
Expand All @@ -43,13 +46,6 @@ public override void ConfigureServices(IServiceCollection services)
});
}

public override void ConfigureContainer(ContainerBuilder builder)
{
base.ConfigureContainer(builder);

// builder.RegisterType<SomeService>().As<ISomeService>(); //if needed override registration with own test fakes
}

public override void Configure(IApplicationBuilder app, IWebHostEnvironment env)
{
var employeesContext = app.ApplicationServices.GetService<EmployeesContext>();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"iisSettings": {
"windowsAuthentication": false,
"anonymousAuthentication": true,
"iisExpress": {
"applicationUrl": "http://localhost:56916/",
"sslPort": 44307
}
},
"profiles": {
"IIS Express": {
"commandName": "IISExpress",
"launchBrowser": true,
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
}
}
}