Skip to content

Commit 360456f

Browse files
Unai Zorrilla CastroUnai Zorrilla Castro
authored andcommitted
Migrated Marketing.API and Locations.API to .NETCoreApp2.0. Update Startup and Program to new .NETCoreApp2.0 templates
1 parent 4e37f0d commit 360456f

11 files changed

Lines changed: 79 additions & 155 deletions

File tree

src/Services/Location/Locations.API/Controllers/HomeController.cs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,4 @@
1-
using System;
2-
using System.Collections.Generic;
3-
using System.Linq;
4-
using System.Threading.Tasks;
5-
using Microsoft.AspNetCore.Mvc;
1+
using Microsoft.AspNetCore.Mvc;
62

73
// For more information on enabling MVC for empty projects, visit https://go.microsoft.com/fwlink/?LinkID=397860
84

src/Services/Location/Locations.API/Infrastructure/Repositories/ILocationsRepository.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
namespace Microsoft.eShopOnContainers.Services.Locations.API.Infrastructure.Repositories
22
{
33
using Microsoft.eShopOnContainers.Services.Locations.API.Model;
4-
using ViewModel;
54
using System.Collections.Generic;
65
using System.Threading.Tasks;
6+
using ViewModel;
77

88
public interface ILocationsRepository
99
{

src/Services/Location/Locations.API/Infrastructure/Services/LocationsService.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
namespace Microsoft.eShopOnContainers.Services.Locations.API.Infrastructure.Services
22
{
3-
using Microsoft.eShopOnContainers.Services.Locations.API.IntegrationEvents.Events;
43
using Microsoft.eShopOnContainers.BuildingBlocks.EventBus.Abstractions;
54
using Microsoft.eShopOnContainers.Services.Locations.API.Infrastructure.Exceptions;
65
using Microsoft.eShopOnContainers.Services.Locations.API.Infrastructure.Repositories;
6+
using Microsoft.eShopOnContainers.Services.Locations.API.IntegrationEvents.Events;
77
using Microsoft.eShopOnContainers.Services.Locations.API.Model;
88
using Microsoft.eShopOnContainers.Services.Locations.API.ViewModel;
99
using System;

src/Services/Location/Locations.API/Locations.API.csproj

Lines changed: 2 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -11,22 +11,7 @@
1111
</ItemGroup>
1212
<ItemGroup>
1313
<PackageReference Include="Autofac.Extensions.DependencyInjection" Version="4.1.0" />
14-
<PackageReference Include="IdentityServer4.AccessTokenValidation" Version="1.2.1" />
15-
<PackageReference Include="Microsoft.ApplicationInsights.AspNetCore" Version="2.1.0-beta6" />
16-
<PackageReference Include="Microsoft.AspNetCore" Version="2.0.0" />
17-
<PackageReference Include="Microsoft.AspNetCore.Mvc" Version="2.0.0" />
18-
<PackageReference Include="Microsoft.AspNetCore.StaticFiles" Version="2.0.0" />
19-
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="2.0.0" />
20-
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="2.0.0" />
21-
<PackageReference Include="Microsoft.EntityFrameworkCore.Relational" Version="2.0.0" />
22-
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="2.0.0" />
23-
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer.Design" Version="2.0.0-preview1-final" />
24-
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="2.0.0" />
25-
<PackageReference Include="Microsoft.Extensions.Configuration.EnvironmentVariables" Version="2.0.0" />
26-
<PackageReference Include="Microsoft.Extensions.Configuration.UserSecrets" Version="2.0.0" />
27-
<PackageReference Include="Microsoft.Extensions.Logging.Debug" Version="2.0.0" />
28-
<PackageReference Include="Microsoft.Extensions.Options" Version="2.0.0" />
29-
<PackageReference Include="Microsoft.Extensions.Options.ConfigurationExtensions" Version="2.0.0" />
14+
<PackageReference Include="Microsoft.AspNetCore.All" Version="2.0.0" />
3015
<PackageReference Include="mongocsharpdriver" Version="2.4.4" />
3116
<PackageReference Include="MongoDB.Bson" Version="2.4.4" />
3217
<PackageReference Include="MongoDB.Driver" Version="2.4.4" />
@@ -35,10 +20,7 @@
3520
<PackageReference Include="Swashbuckle.AspNetCore.SwaggerUi" Version="1.0.0" />
3621
</ItemGroup>
3722
<ItemGroup>
38-
<DotNetCliToolReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Tools" Version="1.0.1" />
39-
</ItemGroup>
40-
<ItemGroup>
41-
<DotNetCliToolReference Include="Microsoft.EntityFrameworkCore.Tools.DotNet" Version="1.0.0" />
23+
<DotNetCliToolReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Tools" Version="2.0.0" />
4224
</ItemGroup>
4325
<ItemGroup>
4426
<ProjectReference Include="..\..\..\BuildingBlocks\EventBus\EventBusRabbitMQ\EventBusRabbitMQ.csproj" />

src/Services/Location/Locations.API/Model/Locations.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
namespace Microsoft.eShopOnContainers.Services.Locations.API.Model
22
{
33
using MongoDB.Bson;
4+
using MongoDB.Bson.Serialization.Attributes;
45
using MongoDB.Driver.GeoJsonObjectModel;
56
using System.Collections.Generic;
6-
using MongoDB.Bson.Serialization.Attributes;
77

88
public class Locations
99
{
Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,28 @@
1-
using System.IO;
1+
using Microsoft.AspNetCore;
22
using Microsoft.AspNetCore.Builder;
33
using Microsoft.AspNetCore.Hosting;
4+
using Microsoft.Extensions.Logging;
5+
using System.IO;
46

57
namespace Microsoft.eShopOnContainers.Services.Locations.API
68
{
79
public class Program
810
{
911
public static void Main(string[] args)
1012
{
11-
var host = new WebHostBuilder()
12-
.UseKestrel()
13+
BuildWebHost(args).Run();
14+
}
15+
16+
public static IWebHost BuildWebHost(string[] args) =>
17+
WebHost.CreateDefaultBuilder(args)
1318
.UseHealthChecks("/hc")
1419
.UseContentRoot(Directory.GetCurrentDirectory())
1520
.UseStartup<Startup>()
16-
.Build();
17-
18-
host.Run();
19-
}
21+
.ConfigureLogging((hostingContext, builder) =>
22+
{
23+
builder.AddConfiguration(hostingContext.Configuration.GetSection("Logging"));
24+
builder.AddConsole();
25+
builder.AddDebug();
26+
}).Build();
2027
}
2128
}

src/Services/Location/Locations.API/Startup.cs

Lines changed: 17 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -3,58 +3,51 @@
33
using Microsoft.AspNetCore.Builder;
44
using Microsoft.AspNetCore.Hosting;
55
using Microsoft.AspNetCore.Http;
6+
using Microsoft.Azure.ServiceBus;
67
using Microsoft.eShopOnContainers.BuildingBlocks.EventBus;
78
using Microsoft.eShopOnContainers.BuildingBlocks.EventBus.Abstractions;
89
using Microsoft.eShopOnContainers.BuildingBlocks.EventBusRabbitMQ;
10+
using Microsoft.eShopOnContainers.BuildingBlocks.EventBusServiceBus;
911
using Microsoft.eShopOnContainers.Services.Locations.API.Infrastructure;
1012
using Microsoft.eShopOnContainers.Services.Locations.API.Infrastructure.Filters;
1113
using Microsoft.eShopOnContainers.Services.Locations.API.Infrastructure.Repositories;
1214
using Microsoft.eShopOnContainers.Services.Locations.API.Infrastructure.Services;
1315
using Microsoft.Extensions.Configuration;
1416
using Microsoft.Extensions.DependencyInjection;
17+
using Microsoft.Extensions.HealthChecks;
1518
using Microsoft.Extensions.Logging;
1619
using RabbitMQ.Client;
17-
using System.Reflection;
20+
using Swashbuckle.AspNetCore.Swagger;
1821
using System;
19-
using Microsoft.eShopOnContainers.BuildingBlocks.EventBusServiceBus;
20-
using Microsoft.Azure.ServiceBus;
2122
using System.Collections.Generic;
22-
using Swashbuckle.AspNetCore.Swagger;
23-
using Microsoft.Extensions.HealthChecks;
2423
using System.Threading.Tasks;
2524

2625
namespace Microsoft.eShopOnContainers.Services.Locations.API
2726
{
2827
public class Startup
2928
{
30-
public IConfigurationRoot Configuration { get; }
31-
32-
public Startup(IHostingEnvironment env)
29+
public Startup(IConfiguration configuration)
3330
{
34-
var builder = new ConfigurationBuilder()
35-
.SetBasePath(env.ContentRootPath)
36-
.AddJsonFile("appsettings.json", optional: false, reloadOnChange: true)
37-
.AddJsonFile($"appsettings.{env.EnvironmentName}.json", optional: true);
38-
39-
if (env.IsDevelopment())
40-
{
41-
builder.AddUserSecrets(typeof(Startup).GetTypeInfo().Assembly);
42-
}
43-
44-
builder.AddEnvironmentVariables();
45-
46-
Configuration = builder.Build();
31+
Configuration = configuration;
4732
}
4833

49-
// This method gets called by the runtime. Use this method to add services to the container.
34+
public IConfiguration Configuration { get; }
35+
5036
public IServiceProvider ConfigureServices(IServiceCollection services)
5137
{
52-
// Add framework services.
5338
services.AddMvc(options =>
5439
{
5540
options.Filters.Add(typeof(HttpGlobalExceptionFilter));
5641
}).AddControllersAsServices();
5742

43+
services.AddAuthentication()
44+
.AddJwtBearer(options =>
45+
{
46+
options.Authority = Configuration.GetValue<string>("IdentityUrl");
47+
options.Audience = "locations";
48+
options.RequireHttpsMetadata = false;
49+
});
50+
5851
services.Configure<LocationSettings>(Configuration);
5952

6053
if (Configuration.GetValue<bool>("AzureServiceBusEnabled"))
@@ -143,14 +136,9 @@ public IServiceProvider ConfigureServices(IServiceCollection services)
143136
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
144137
public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory)
145138
{
146-
//Configure logs
147-
148-
loggerFactory.AddConsole(Configuration.GetSection("Logging"));
149-
loggerFactory.AddDebug();
150-
151139
app.UseCors("CorsPolicy");
152140

153-
ConfigureAuth(app);
141+
app.UseAuthentication();
154142

155143
app.UseMvcWithDefaultRoute();
156144

@@ -165,17 +153,6 @@ public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerF
165153
.Wait();
166154
}
167155

168-
protected virtual void ConfigureAuth(IApplicationBuilder app)
169-
{
170-
var identityUrl = Configuration.GetValue<string>("IdentityUrl");
171-
app.UseIdentityServerAuthentication(new IdentityServerAuthenticationOptions
172-
{
173-
Authority = identityUrl.ToString(),
174-
ApiName = "locations",
175-
RequireHttpsMetadata = false
176-
});
177-
}
178-
179156
private void RegisterEventBus(IServiceCollection services)
180157
{
181158
if (Configuration.GetValue<bool>("AzureServiceBusEnabled"))

src/Services/Location/Locations.API/ViewModel/LocationRequest.cs

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,4 @@
1-
using System;
2-
using System.Collections.Generic;
3-
using System.Linq;
4-
using System.Threading.Tasks;
5-
6-
namespace Microsoft.eShopOnContainers.Services.Locations.API.ViewModel
1+
namespace Microsoft.eShopOnContainers.Services.Locations.API.ViewModel
72
{
83
public class LocationRequest
94
{

src/Services/Marketing/Marketing.API/Marketing.API.csproj

Lines changed: 2 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -18,39 +18,15 @@
1818
</ItemGroup>
1919
<ItemGroup>
2020
<PackageReference Include="Autofac.Extensions.DependencyInjection" Version="4.1.0" />
21-
<PackageReference Include="IdentityServer4.AccessTokenValidation" Version="1.2.1" />
22-
<PackageReference Include="Microsoft.AspNetCore" Version="2.0.0" />
23-
<PackageReference Include="Microsoft.AspNetCore.Mvc" Version="2.0.0" />
24-
<PackageReference Include="Microsoft.AspNetCore.StaticFiles" Version="2.0.0" />
25-
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="2.0.0" />
26-
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="2.0.0" />
27-
<PackageReference Include="Microsoft.EntityFrameworkCore.Relational" Version="2.0.0" />
28-
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="2.0.0" />
29-
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer.Design" Version="2.0.0-preview1-final" />
30-
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="2.0.0" />
31-
<PackageReference Include="Microsoft.Extensions.Configuration" Version="2.0.0" />
32-
<PackageReference Include="Microsoft.Extensions.Configuration.Abstractions" Version="2.0.0" />
33-
<PackageReference Include="Microsoft.Extensions.Configuration.EnvironmentVariables" Version="2.0.0" />
34-
<PackageReference Include="Microsoft.Extensions.Configuration.FileExtensions" Version="2.0.0" />
35-
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="2.0.0" />
36-
<PackageReference Include="Microsoft.Extensions.Configuration.UserSecrets" Version="2.0.0" />
37-
<PackageReference Include="Microsoft.Extensions.Logging" Version="2.0.0" />
38-
<PackageReference Include="Microsoft.Extensions.Logging.Console" Version="2.0.0" />
39-
<PackageReference Include="Microsoft.Extensions.Logging.Debug" Version="2.0.0" />
40-
<PackageReference Include="Microsoft.Extensions.Options" Version="2.0.0" />
41-
<PackageReference Include="Microsoft.Extensions.Options.ConfigurationExtensions" Version="2.0.0" />
42-
<PackageReference Include="Microsoft.VisualStudio.Web.BrowserLink" Version="2.0.0" />
21+
<PackageReference Include="Microsoft.AspNetCore.All" Version="2.0.0" />
4322
<PackageReference Include="mongocsharpdriver" Version="2.4.4" />
4423
<PackageReference Include="MongoDB.Bson" Version="2.4.4" />
4524
<PackageReference Include="MongoDB.Driver" Version="2.4.4" />
4625
<PackageReference Include="MongoDB.Driver.Core" Version="2.4.4" />
4726
<PackageReference Include="Swashbuckle.AspNetCore" Version="1.0.0" />
4827
</ItemGroup>
4928
<ItemGroup>
50-
<DotNetCliToolReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Tools" Version="1.0.1" />
51-
</ItemGroup>
52-
<ItemGroup>
53-
<DotNetCliToolReference Include="Microsoft.EntityFrameworkCore.Tools.DotNet" Version="1.0.0" />
29+
<DotNetCliToolReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Tools" Version="2.0.0" />
5430
</ItemGroup>
5531
<ItemGroup>
5632
<ProjectReference Include="..\..\..\BuildingBlocks\EventBus\EventBusRabbitMQ\EventBusRabbitMQ.csproj" />
Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,28 @@
11
namespace Microsoft.eShopOnContainers.Services.Marketing.API
22
{
3-
using System.IO;
43
using AspNetCore.Hosting;
4+
using Microsoft.AspNetCore;
5+
using Microsoft.Extensions.Logging;
6+
using System.IO;
57

68
public class Program
79
{
810
public static void Main(string[] args)
911
{
10-
var host = new WebHostBuilder()
11-
.UseKestrel()
12+
BuildWebHost(args).Run();
13+
}
14+
15+
public static IWebHost BuildWebHost(string[] args) =>
16+
WebHost.CreateDefaultBuilder(args)
1217
.UseHealthChecks("/hc")
1318
.UseContentRoot(Directory.GetCurrentDirectory())
1419
.UseStartup<Startup>()
1520
.UseWebRoot("Pics")
16-
.Build();
17-
18-
host.Run();
19-
}
21+
.ConfigureLogging((hostingContext, builder) =>
22+
{
23+
builder.AddConfiguration(hostingContext.Configuration.GetSection("Logging"));
24+
builder.AddConsole();
25+
builder.AddDebug();
26+
}).Build();
2027
}
2128
}

0 commit comments

Comments
 (0)