@ -0,0 +1,106 @@ | |||
using System; | |||
using System.Collections.Generic; | |||
using System.Linq; | |||
using System.Threading.Tasks; | |||
using Microsoft.AspNetCore.Http; | |||
using Microsoft.AspNetCore.Mvc; | |||
using Microsoft.EntityFrameworkCore; | |||
using TenantManager.Database; | |||
using TenantManager.Models; | |||
namespace TenantManager.Controllers | |||
{ | |||
[Route("api/[controller]")] | |||
[ApiController] | |||
public class CustomisationsController : ControllerBase | |||
{ | |||
private readonly TenantManagerContext _context; | |||
public CustomisationsController(TenantManagerContext context) | |||
{ | |||
_context = context; | |||
} | |||
// GET: api/Customisations | |||
[HttpGet] | |||
public async Task<ActionResult<IEnumerable<Customisation>>> GetCustomisation() | |||
{ | |||
return await _context.Customisation.ToListAsync(); | |||
} | |||
// GET: api/Customisations/5 | |||
[HttpGet("{id}")] | |||
public async Task<ActionResult<Customisation>> GetCustomisation(int id) | |||
{ | |||
var customisation = await _context.Customisation.FindAsync(id); | |||
if (customisation == null) | |||
{ | |||
return NotFound(); | |||
} | |||
return customisation; | |||
} | |||
// PUT: api/Customisations/5 | |||
[HttpPut("{id}")] | |||
public async Task<IActionResult> PutCustomisation(int id, Customisation customisation) | |||
{ | |||
if (id != customisation.CustomisationId) | |||
{ | |||
return BadRequest(); | |||
} | |||
_context.Entry(customisation).State = EntityState.Modified; | |||
try | |||
{ | |||
await _context.SaveChangesAsync(); | |||
} | |||
catch (DbUpdateConcurrencyException) | |||
{ | |||
if (!CustomisationExists(id)) | |||
{ | |||
return NotFound(); | |||
} | |||
else | |||
{ | |||
throw; | |||
} | |||
} | |||
return NoContent(); | |||
} | |||
// POST: api/Customisations | |||
[HttpPost] | |||
public async Task<ActionResult<Customisation>> PostCustomisation(Customisation customisation) | |||
{ | |||
_context.Customisation.Add(customisation); | |||
await _context.SaveChangesAsync(); | |||
return CreatedAtAction("GetCustomisation", new { id = customisation.CustomisationId }, customisation); | |||
} | |||
// DELETE: api/Customisations/5 | |||
[HttpDelete("{id}")] | |||
public async Task<ActionResult<Customisation>> DeleteCustomisation(int id) | |||
{ | |||
var customisation = await _context.Customisation.FindAsync(id); | |||
if (customisation == null) | |||
{ | |||
return NotFound(); | |||
} | |||
_context.Customisation.Remove(customisation); | |||
await _context.SaveChangesAsync(); | |||
return customisation; | |||
} | |||
private bool CustomisationExists(int id) | |||
{ | |||
return _context.Customisation.Any(e => e.CustomisationId == id); | |||
} | |||
} | |||
} |
@ -0,0 +1,106 @@ | |||
using System; | |||
using System.Collections.Generic; | |||
using System.Linq; | |||
using System.Threading.Tasks; | |||
using Microsoft.AspNetCore.Http; | |||
using Microsoft.AspNetCore.Mvc; | |||
using Microsoft.EntityFrameworkCore; | |||
using TenantManager.Database; | |||
using TenantManager.Models; | |||
namespace TenantManager.Controllers | |||
{ | |||
[Route("api/[controller]")] | |||
[ApiController] | |||
public class MethodsController : ControllerBase | |||
{ | |||
private readonly TenantManagerContext _context; | |||
public MethodsController(TenantManagerContext context) | |||
{ | |||
_context = context; | |||
} | |||
// GET: api/Methods | |||
[HttpGet] | |||
public async Task<ActionResult<IEnumerable<Method>>> GetMethod() | |||
{ | |||
return await _context.Method.ToListAsync(); | |||
} | |||
// GET: api/Methods/5 | |||
[HttpGet("{id}")] | |||
public async Task<ActionResult<Method>> GetMethod(int id) | |||
{ | |||
var @method = await _context.Method.FindAsync(id); | |||
if (@method == null) | |||
{ | |||
return NotFound(); | |||
} | |||
return @method; | |||
} | |||
// PUT: api/Methods/5 | |||
[HttpPut("{id}")] | |||
public async Task<IActionResult> PutMethod(int id, Method @method) | |||
{ | |||
if (id != @method.MethodId) | |||
{ | |||
return BadRequest(); | |||
} | |||
_context.Entry(@method).State = EntityState.Modified; | |||
try | |||
{ | |||
await _context.SaveChangesAsync(); | |||
} | |||
catch (DbUpdateConcurrencyException) | |||
{ | |||
if (!MethodExists(id)) | |||
{ | |||
return NotFound(); | |||
} | |||
else | |||
{ | |||
throw; | |||
} | |||
} | |||
return NoContent(); | |||
} | |||
// POST: api/Methods | |||
[HttpPost] | |||
public async Task<ActionResult<Method>> PostMethod(Method @method) | |||
{ | |||
_context.Method.Add(@method); | |||
await _context.SaveChangesAsync(); | |||
return CreatedAtAction("GetMethod", new { id = @method.MethodId }, @method); | |||
} | |||
// DELETE: api/Methods/5 | |||
[HttpDelete("{id}")] | |||
public async Task<ActionResult<Method>> DeleteMethod(int id) | |||
{ | |||
var @method = await _context.Method.FindAsync(id); | |||
if (@method == null) | |||
{ | |||
return NotFound(); | |||
} | |||
_context.Method.Remove(@method); | |||
await _context.SaveChangesAsync(); | |||
return @method; | |||
} | |||
private bool MethodExists(int id) | |||
{ | |||
return _context.Method.Any(e => e.MethodId == id); | |||
} | |||
} | |||
} |
@ -0,0 +1,105 @@ | |||
using System; | |||
using System.Collections.Generic; | |||
using System.Linq; | |||
using System.Threading.Tasks; | |||
using Microsoft.AspNetCore.Http; | |||
using Microsoft.AspNetCore.Mvc; | |||
using Microsoft.EntityFrameworkCore; | |||
using TenantManager.Models; | |||
namespace TenantManager.Database | |||
{ | |||
[Route("api/[controller]")] | |||
[ApiController] | |||
public class TenantsController : ControllerBase | |||
{ | |||
private readonly TenantManagerContext _context; | |||
public TenantsController(TenantManagerContext context) | |||
{ | |||
_context = context; | |||
} | |||
// GET: api/Tenants | |||
[HttpGet] | |||
public async Task<ActionResult<IEnumerable<Tenant>>> GetTenant() | |||
{ | |||
return await _context.Tenant.ToListAsync(); | |||
} | |||
// GET: api/Tenants/5 | |||
[HttpGet("{id}")] | |||
public async Task<ActionResult<Tenant>> GetTenant(long id) | |||
{ | |||
var tenant = await _context.Tenant.FindAsync(id); | |||
if (tenant == null) | |||
{ | |||
return NotFound(); | |||
} | |||
return tenant; | |||
} | |||
// PUT: api/Tenants/5 | |||
[HttpPut("{id}")] | |||
public async Task<IActionResult> PutTenant(long id, Tenant tenant) | |||
{ | |||
if (id != tenant.TenantId) | |||
{ | |||
return BadRequest(); | |||
} | |||
_context.Entry(tenant).State = EntityState.Modified; | |||
try | |||
{ | |||
await _context.SaveChangesAsync(); | |||
} | |||
catch (DbUpdateConcurrencyException) | |||
{ | |||
if (!TenantExists(id)) | |||
{ | |||
return NotFound(); | |||
} | |||
else | |||
{ | |||
throw; | |||
} | |||
} | |||
return NoContent(); | |||
} | |||
// POST: api/Tenants | |||
[HttpPost] | |||
public async Task<ActionResult<Tenant>> PostTenant(Tenant tenant) | |||
{ | |||
_context.Tenant.Add(tenant); | |||
await _context.SaveChangesAsync(); | |||
return CreatedAtAction("GetTenant", new { id = tenant.TenantId }, tenant); | |||
} | |||
// DELETE: api/Tenants/5 | |||
[HttpDelete("{id}")] | |||
public async Task<ActionResult<Tenant>> DeleteTenant(long id) | |||
{ | |||
var tenant = await _context.Tenant.FindAsync(id); | |||
if (tenant == null) | |||
{ | |||
return NotFound(); | |||
} | |||
_context.Tenant.Remove(tenant); | |||
await _context.SaveChangesAsync(); | |||
return tenant; | |||
} | |||
private bool TenantExists(long id) | |||
{ | |||
return _context.Tenant.Any(e => e.TenantId == id); | |||
} | |||
} | |||
} |
@ -0,0 +1,45 @@ | |||
using System; | |||
using System.Collections.Generic; | |||
using System.Linq; | |||
using System.Threading.Tasks; | |||
using Microsoft.AspNetCore.Mvc; | |||
namespace TenantManager.Controllers | |||
{ | |||
[Route("api/[controller]")] | |||
[ApiController] | |||
public class ValuesController : ControllerBase | |||
{ | |||
// GET api/values | |||
[HttpGet] | |||
public ActionResult<IEnumerable<string>> Get() | |||
{ | |||
return new string[] { "value1", "value2" }; | |||
} | |||
// GET api/values/5 | |||
[HttpGet("{id}")] | |||
public ActionResult<string> Get(int id) | |||
{ | |||
return "value"; | |||
} | |||
// POST api/values | |||
[HttpPost] | |||
public void Post([FromBody] string value) | |||
{ | |||
} | |||
// PUT api/values/5 | |||
[HttpPut("{id}")] | |||
public void Put(int id, [FromBody] string value) | |||
{ | |||
} | |||
// DELETE api/values/5 | |||
[HttpDelete("{id}")] | |||
public void Delete(int id) | |||
{ | |||
} | |||
} | |||
} |
@ -0,0 +1,35 @@ | |||
using System; | |||
using System.Collections.Generic; | |||
using System.Linq; | |||
using System.Threading.Tasks; | |||
using Microsoft.EntityFrameworkCore; | |||
using Microsoft.EntityFrameworkCore.Design; | |||
using TenantManager.Models; | |||
namespace TenantManager.Database | |||
{ | |||
public class TenantManagerContext : DbContext | |||
{ | |||
public TenantManagerContext (DbContextOptions<TenantManagerContext> options) | |||
: base(options) | |||
{ | |||
} | |||
public DbSet<TenantManager.Models.Tenant> Tenant { get; set; } | |||
public DbSet<TenantManager.Models.Method> Method { get; set; } | |||
public DbSet<TenantManager.Models.Customisation> Customisation { get; set; } | |||
} | |||
public class TenantManagerContextDesignFactory : IDesignTimeDbContextFactory<TenantManagerContext> | |||
{ | |||
public TenantManagerContext CreateDbContext(string[] args) | |||
{ | |||
var optionsBuilder = new DbContextOptionsBuilder<TenantManagerContext>() | |||
.UseSqlServer("Server=.;Initial Catalog=Microsoft.eShopOnContainers.Services.TenantManagerDb;Integrated Security=true"); | |||
return new TenantManagerContext(optionsBuilder.Options); | |||
} | |||
} | |||
} |
@ -0,0 +1,70 @@ | |||
using System; | |||
using System.Collections.Generic; | |||
using System.Linq; | |||
using System.Threading.Tasks; | |||
using TenantManager.Models; | |||
namespace TenantManager.Database | |||
{ | |||
public static class DbInitializer | |||
{ | |||
public static void Initialize(TenantManagerContext context) | |||
{ | |||
context.Database.EnsureCreated(); | |||
if (context.Tenant.Any()) | |||
{ | |||
return; | |||
} | |||
var tenant1 = new Tenant() { TenantName = "Tekna" }; | |||
var tenant2 = new Tenant() { TenantName = "NITO" }; | |||
var tenant3 = new Tenant() { TenantName = "LO" }; | |||
var tenants = new Tenant[] | |||
{ | |||
tenant1, | |||
tenant2, | |||
tenant3 | |||
}; | |||
foreach(Tenant t in tenants) | |||
{ | |||
context.Tenant.Add(t); | |||
} | |||
context.SaveChanges(); | |||
var method1 = new Method() { MethodName = "GetPrice" }; | |||
var method2 = new Method() { MethodName = "GetItem" }; | |||
var methods = new Method[] | |||
{ | |||
method1, | |||
method2 | |||
}; | |||
foreach(Method m in methods) | |||
{ | |||
context.Method.Add(m); | |||
} | |||
context.SaveChanges(); | |||
var customisations = new Customisation[] | |||
{ | |||
new Customisation(){Tenant=tenant1, Method=method1 }, | |||
new Customisation(){Tenant=tenant1, Method=method2}, | |||
new Customisation(){Tenant=tenant2, Method=method1 } | |||
}; | |||
foreach(Customisation c in customisations) | |||
{ | |||
context.Add(c); | |||
} | |||
context.SaveChanges(); | |||
} | |||
} | |||
} |
@ -0,0 +1,59 @@ | |||
FROM mcr.microsoft.com/dotnet/core/aspnet:2.2-stretch-slim AS base | |||
WORKDIR /app | |||
EXPOSE 80 | |||
FROM mcr.microsoft.com/dotnet/core/sdk:2.2-stretch AS build | |||
WORKDIR /src | |||
# Keep the project list and command dotnet restore identical in all Dockfiles to maximize image cache utilization | |||
COPY eShopOnContainers-ServicesAndWebApps.sln . | |||
COPY docker-compose.dcproj /src/ | |||
COPY src/ApiGateways/ApiGw-Base/OcelotApiGw.csproj src/ApiGateways/ApiGw-Base/ | |||
COPY src/ApiGateways/Mobile.Bff.Shopping/aggregator/Mobile.Shopping.HttpAggregator.csproj src/ApiGateways/Mobile.Bff.Shopping/aggregator/ | |||
COPY src/ApiGateways/Web.Bff.Shopping/aggregator/Web.Shopping.HttpAggregator.csproj src/ApiGateways/Web.Bff.Shopping/aggregator/ | |||
COPY src/BuildingBlocks/Devspaces.Support/Devspaces.Support.csproj src/BuildingBlocks/Devspaces.Support/ | |||
COPY src/BuildingBlocks/EventBus/EventBus/EventBus.csproj src/BuildingBlocks/EventBus/EventBus/ | |||
COPY src/BuildingBlocks/EventBus/EventBus.Tests/EventBus.Tests.csproj src/BuildingBlocks/EventBus/EventBus.Tests/ | |||
COPY src/BuildingBlocks/EventBus/EventBusRabbitMQ/EventBusRabbitMQ.csproj src/BuildingBlocks/EventBus/EventBusRabbitMQ/ | |||
COPY src/BuildingBlocks/EventBus/EventBusServiceBus/EventBusServiceBus.csproj src/BuildingBlocks/EventBus/EventBusServiceBus/ | |||
COPY src/BuildingBlocks/EventBus/IntegrationEventLogEF/IntegrationEventLogEF.csproj src/BuildingBlocks/EventBus/IntegrationEventLogEF/ | |||
COPY src/BuildingBlocks/WebHostCustomization/WebHost.Customization/WebHost.Customization.csproj src/BuildingBlocks/WebHostCustomization/WebHost.Customization/ | |||
COPY src/Services/Basket/Basket.API/Basket.API.csproj src/Services/Basket/Basket.API/ | |||
COPY src/Services/Basket/Basket.FunctionalTests/Basket.FunctionalTests.csproj src/Services/Basket/Basket.FunctionalTests/ | |||
COPY src/Services/Basket/Basket.UnitTests/Basket.UnitTests.csproj src/Services/Basket/Basket.UnitTests/ | |||
COPY src/Services/Catalog/Catalog.API/Catalog.API.csproj src/Services/Catalog/Catalog.API/ | |||
COPY src/Services/Catalog/Catalog.FunctionalTests/Catalog.FunctionalTests.csproj src/Services/Catalog/Catalog.FunctionalTests/ | |||
COPY src/Services/Catalog/Catalog.UnitTests/Catalog.UnitTests.csproj src/Services/Catalog/Catalog.UnitTests/ | |||
COPY src/Services/Identity/Identity.API/Identity.API.csproj src/Services/Identity/Identity.API/ | |||
COPY src/Services/Location/Locations.API/Locations.API.csproj src/Services/Location/Locations.API/ | |||
COPY src/Services/Location/Locations.FunctionalTests/Locations.FunctionalTests.csproj src/Services/Location/Locations.FunctionalTests/ | |||
COPY src/Services/Marketing/Marketing.API/Marketing.API.csproj src/Services/Marketing/Marketing.API/ | |||
COPY src/Services/Marketing/Marketing.FunctionalTests/Marketing.FunctionalTests.csproj src/Services/Marketing/Marketing.FunctionalTests/ | |||
COPY src/Services/Ordering/Ordering.API/Ordering.API.csproj src/Services/Ordering/Ordering.API/ | |||
COPY src/Services/Ordering/Ordering.BackgroundTasks/Ordering.BackgroundTasks.csproj src/Services/Ordering/Ordering.BackgroundTasks/ | |||
COPY src/Services/Ordering/Ordering.Domain/Ordering.Domain.csproj src/Services/Ordering/Ordering.Domain/ | |||
COPY src/Services/Ordering/Ordering.FunctionalTests/Ordering.FunctionalTests.csproj src/Services/Ordering/Ordering.FunctionalTests/ | |||
COPY src/Services/Ordering/Ordering.Infrastructure/Ordering.Infrastructure.csproj src/Services/Ordering/Ordering.Infrastructure/ | |||
COPY src/Services/Ordering/Ordering.SignalrHub/Ordering.SignalrHub.csproj src/Services/Ordering/Ordering.SignalrHub/ | |||
COPY src/Services/Ordering/Ordering.UnitTests/Ordering.UnitTests.csproj src/Services/Ordering/Ordering.UnitTests/ | |||
COPY src/Services/Payment/Payment.API/Payment.API.csproj src/Services/Payment/Payment.API/ | |||
COPY src/Services/Webhooks/Webhooks.API/Webhooks.API.csproj src/Services/Webhooks/Webhooks.API/ | |||
COPY src/Web/WebhookClient/WebhookClient.csproj src/Web/WebhookClient/ | |||
COPY src/Web/WebMVC/WebMVC.csproj src/Web/WebMVC/ | |||
COPY src/Web/WebSPA/WebSPA.csproj src/Web/WebSPA/ | |||
COPY src/Web/WebStatus/WebStatus.csproj src/Web/WebStatus/ | |||
COPY test/ServicesTests/Application.FunctionalTests/Application.FunctionalTests.csproj test/ServicesTests/Application.FunctionalTests/ | |||
COPY test/ServicesTests/LoadTest/LoadTest.csproj test/ServicesTests/LoadTest/ | |||
RUN dotnet restore eShopOnContainers-ServicesAndWebApps.sln | |||
COPY . . | |||
WORKDIR /src/src/Services/TenantManager/TenantManager | |||
RUN dotnet publish --no-restore -c Release -o /app | |||
FROM build AS publish | |||
FROM base AS final | |||
WORKDIR /app | |||
COPY --from=publish /app . | |||
ENTRYPOINT ["dotnet", "TenantManager.dll"] |
@ -0,0 +1,16 @@ | |||
using System; | |||
using System.Collections.Generic; | |||
using System.Linq; | |||
using System.Threading.Tasks; | |||
namespace TenantManager.Models | |||
{ | |||
public class Customisation | |||
{ | |||
public int CustomisationId { get; set; } | |||
public int TenantId { get; set; } | |||
public virtual Tenant Tenant { get; set; } | |||
public int MethodId { get; set; } | |||
public virtual Method Method { get; set; } | |||
} | |||
} |
@ -0,0 +1,15 @@ | |||
using System; | |||
using System.Collections.Generic; | |||
using System.ComponentModel.DataAnnotations; | |||
using System.Linq; | |||
using System.Threading.Tasks; | |||
namespace TenantManager.Models | |||
{ | |||
public class Method | |||
{ | |||
public int MethodId { get; set; } | |||
public String MethodName { get; set; } | |||
public ICollection<Customisation> Customisations { get; set; } | |||
} | |||
} |
@ -0,0 +1,16 @@ | |||
using System; | |||
using System.Collections.Generic; | |||
using System.ComponentModel.DataAnnotations; | |||
using System.Linq; | |||
using System.Threading.Tasks; | |||
namespace TenantManager.Models | |||
{ | |||
public class Tenant | |||
{ | |||
public String TenantName { get; set; } | |||
[Key] | |||
public long TenantId { get; set; } | |||
public ICollection<Customisation> Customisations { get; set; } | |||
} | |||
} |
@ -0,0 +1,44 @@ | |||
using System; | |||
using System.Collections.Generic; | |||
using System.IO; | |||
using System.Linq; | |||
using System.Threading.Tasks; | |||
using Microsoft.AspNetCore; | |||
using Microsoft.AspNetCore.Hosting; | |||
using Microsoft.Extensions.Configuration; | |||
using Microsoft.Extensions.DependencyInjection; | |||
using Microsoft.Extensions.Logging; | |||
using TenantManager.Database; | |||
namespace TenantManager | |||
{ | |||
public class Program | |||
{ | |||
public static void Main(string[] args) | |||
{ | |||
var host = CreateWebHostBuilder(args).Build(); | |||
using (var scope = host.Services.CreateScope()) | |||
{ | |||
var services = scope.ServiceProvider; | |||
try | |||
{ | |||
var context = services.GetRequiredService<TenantManagerContext>(); | |||
DbInitializer.Initialize(context); | |||
} | |||
catch (Exception ex) | |||
{ | |||
var logger = services.GetRequiredService<ILogger<Program>>(); | |||
logger.LogError(ex, "An error occurred creating the DB."); | |||
} | |||
} | |||
host.Run(); | |||
} | |||
public static IWebHostBuilder CreateWebHostBuilder(string[] args) => | |||
WebHost.CreateDefaultBuilder(args) | |||
.UseStartup<Startup>(); | |||
} | |||
} |
@ -0,0 +1,42 @@ | |||
{ | |||
"iisSettings": { | |||
"windowsAuthentication": false, | |||
"anonymousAuthentication": true, | |||
"iisExpress": { | |||
"applicationUrl": "http://localhost:62897", | |||
"sslPort": 44318 | |||
} | |||
}, | |||
"$schema": "http://json.schemastore.org/launchsettings.json", | |||
"profiles": { | |||
"IIS Express": { | |||
"commandName": "IISExpress", | |||
"launchBrowser": true, | |||
"launchUrl": "api/values", | |||
"environmentVariables": { | |||
"ASPNETCORE_ENVIRONMENT": "Development" | |||
} | |||
}, | |||
"TenantManager": { | |||
"commandName": "Project", | |||
"launchBrowser": true, | |||
"launchUrl": "api/values", | |||
"environmentVariables": { | |||
"ASPNETCORE_ENVIRONMENT": "Development" | |||
}, | |||
"applicationUrl": "https://localhost:5001;http://localhost:5000" | |||
}, | |||
"Docker": { | |||
"commandName": "Docker", | |||
"launchBrowser": true, | |||
"launchUrl": "{Scheme}://{ServiceHost}:{ServicePort}/api/values", | |||
"environmentVariables": { | |||
"ASPNETCORE_URLS": "https://+:443;http://+:80", | |||
"ASPNETCORE_HTTPS_PORT": "44319" | |||
}, | |||
"httpPort": 62898, | |||
"useSSL": true, | |||
"sslPort": 44319 | |||
} | |||
} | |||
} |
@ -0,0 +1,134 @@ | |||
using System; | |||
using System.Collections.Generic; | |||
using System.Linq; | |||
using System.Threading.Tasks; | |||
using Microsoft.AspNetCore.Builder; | |||
using Microsoft.AspNetCore.Hosting; | |||
using Microsoft.AspNetCore.HttpsPolicy; | |||
using Microsoft.AspNetCore.Mvc; | |||
using Microsoft.Extensions.Configuration; | |||
using Microsoft.Extensions.DependencyInjection; | |||
using Microsoft.Extensions.Logging; | |||
using Microsoft.Extensions.Options; | |||
using Microsoft.EntityFrameworkCore; | |||
using TenantManager.Database; | |||
using Microsoft.EntityFrameworkCore.Diagnostics; | |||
using System.Reflection; | |||
using Autofac; | |||
using Autofac.Extensions.DependencyInjection; | |||
using Microsoft.AspNetCore.Http; | |||
namespace TenantManager | |||
{ | |||
public static class CustomExtensionMethods | |||
{ | |||
public static IServiceCollection AddCustomDbContext(this IServiceCollection services, IConfiguration configuration) | |||
{ | |||
services.AddDbContext<TenantManagerContext>(options => | |||
options.UseSqlServer(configuration["ConnectionString"])); | |||
//services.AddDbContext<TenantManagerContext>(options => | |||
//{ | |||
// options.UseSqlServer(configuration["ConnectionString"], | |||
// sqlServerOptionsAction: sqlOptions => | |||
// { | |||
// sqlOptions.MigrationsAssembly(typeof(Startup).GetTypeInfo().Assembly.GetName().Name); | |||
// //Configuring Connection Resiliency: https://docs.microsoft.com/en-us/ef/core/miscellaneous/connection-resiliency | |||
// sqlOptions.EnableRetryOnFailure(maxRetryCount: 10, maxRetryDelay: TimeSpan.FromSeconds(30), errorNumbersToAdd: null); | |||
// }); | |||
// // Changing default behavior when client evaluation occurs to throw. | |||
// // Default in EF Core would be to log a warning when client evaluation is performed. | |||
// options.ConfigureWarnings(warnings => warnings.Throw(RelationalEventId.QueryClientEvaluationWarning)); | |||
// //Check Client vs. Server evaluation: https://docs.microsoft.com/en-us/ef/core/querying/client-eval | |||
//}); | |||
return services; | |||
} | |||
public static IServiceCollection AddCustomMvc(this IServiceCollection services) | |||
{ | |||
// Add framework services. | |||
services.AddMvc() | |||
.SetCompatibilityVersion(CompatibilityVersion.Version_2_2) | |||
.AddControllersAsServices(); //Injecting Controllers themselves thru DI | |||
//For further info see: http://docs.autofac.org/en/latest/integration/aspnetcore.html#controllers-as-services | |||
services.AddCors(options => | |||
{ | |||
options.AddPolicy("CorsPolicy", | |||
builder => builder | |||
.SetIsOriginAllowed((host) => true) | |||
.AllowAnyMethod() | |||
.AllowAnyHeader() | |||
.AllowCredentials()); | |||
}); | |||
return services; | |||
} | |||
public static IServiceCollection AddCustomConfiguration(this IServiceCollection services, IConfiguration configuration) | |||
{ | |||
services.AddOptions(); | |||
services.Configure<TenantManagerSettings>(configuration); | |||
services.Configure<ApiBehaviorOptions>(options => | |||
{ | |||
options.InvalidModelStateResponseFactory = context => | |||
{ | |||
var problemDetails = new ValidationProblemDetails(context.ModelState) | |||
{ | |||
Instance = context.HttpContext.Request.Path, | |||
Status = StatusCodes.Status400BadRequest, | |||
Detail = "Please refer to the errors property for additional details." | |||
}; | |||
return new BadRequestObjectResult(problemDetails) | |||
{ | |||
ContentTypes = { "application/problem+json", "application/problem+xml" } | |||
}; | |||
}; | |||
}); | |||
return services; | |||
} | |||
} | |||
public class Startup | |||
{ | |||
public Startup(IConfiguration configuration) | |||
{ | |||
Configuration = configuration; | |||
} | |||
public IConfiguration Configuration { get; } | |||
// This method gets called by the runtime. Use this method to add services to the container. | |||
public IServiceProvider ConfigureServices(IServiceCollection services) | |||
{ | |||
services | |||
.AddCustomDbContext(Configuration) | |||
.AddCustomMvc() | |||
.AddCustomConfiguration(Configuration); | |||
var container = new ContainerBuilder(); | |||
container.Populate(services); | |||
return new AutofacServiceProvider(container.Build()); | |||
} | |||
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline. | |||
public void Configure(IApplicationBuilder app, IHostingEnvironment env) | |||
{ | |||
if (env.IsDevelopment()) | |||
{ | |||
app.UseDeveloperExceptionPage(); | |||
} | |||
else | |||
{ | |||
// The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts. | |||
app.UseHsts(); | |||
} | |||
app.UseHttpsRedirection(); | |||
app.UseMvc(); | |||
} | |||
} | |||
} |
@ -0,0 +1,25 @@ | |||
<Project Sdk="Microsoft.NET.Sdk.Web"> | |||
<PropertyGroup> | |||
<TargetFramework>netcoreapp2.2</TargetFramework> | |||
<AspNetCoreHostingModel>InProcess</AspNetCoreHostingModel> | |||
<UserSecretsId>32cd2988-8f43-4aff-88af-6a3397a7d2e6</UserSecretsId> | |||
<DockerDefaultTargetOS>Linux</DockerDefaultTargetOS> | |||
<DockerComposeProjectPath>..\..\..\..\docker-compose.dcproj</DockerComposeProjectPath> | |||
</PropertyGroup> | |||
<ItemGroup> | |||
<PackageReference Include="Autofac" Version="4.6.2" /> | |||
<PackageReference Include="Autofac.Extensions.DependencyInjection" Version="4.2.1" /> | |||
<PackageReference Include="Microsoft.AspNetCore.App" /> | |||
<PackageReference Include="Microsoft.AspNetCore.Razor.Design" Version="2.2.0" PrivateAssets="All" /> | |||
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="2.2.6" /> | |||
<PackageReference Include="Microsoft.VisualStudio.Azure.Containers.Tools.Targets" Version="1.7.12" /> | |||
<PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Design" Version="2.2.3" /> | |||
</ItemGroup> | |||
<ItemGroup> | |||
<Folder Include="Infrastructure\Filters\" /> | |||
</ItemGroup> | |||
</Project> |
@ -0,0 +1,13 @@ | |||
using System; | |||
using System.Collections.Generic; | |||
using System.Linq; | |||
using System.Threading.Tasks; | |||
namespace TenantManager | |||
{ | |||
public class TenantManagerSettings | |||
{ | |||
public string ConnectionString { get; set; } | |||
} | |||
} |
@ -0,0 +1,9 @@ | |||
{ | |||
"Logging": { | |||
"LogLevel": { | |||
"Default": "Debug", | |||
"System": "Information", | |||
"Microsoft": "Information" | |||
} | |||
} | |||
} |
@ -0,0 +1,9 @@ | |||
{ | |||
"Logging": { | |||
"LogLevel": { | |||
"Default": "Warning" | |||
} | |||
}, | |||
"AllowedHosts": "*", | |||
"ConnectionString": "Server=tcp:127.0.0.1,5433;Database=Microsoft.eShopOnContainers.Services.TenantManagerDb;User Id=sa;Password=Pass@word;" | |||
} |