@ -0,0 +1,3 @@ | |||||
* | |||||
!obj/Docker/publish/* | |||||
!obj/Docker/empty/ |
@ -0,0 +1,36 @@ | |||||
namespace Microsoft.eShopOnContainers.Services.Marketing.API.Controllers | |||||
{ | |||||
using System.Collections.Generic; | |||||
using Microsoft.AspNetCore.Mvc; | |||||
[Route("api/[controller]")] | |||||
public class CampaignsController : Controller | |||||
{ | |||||
[HttpGet] | |||||
public IEnumerable<string> Get() | |||||
{ | |||||
return new string[] { "value1", "value2" }; | |||||
} | |||||
[HttpGet("{id:int}")] | |||||
public string Get(int id) | |||||
{ | |||||
return "value"; | |||||
} | |||||
[HttpPost] | |||||
public void Post([FromBody]string value) | |||||
{ | |||||
} | |||||
[HttpPut("{id:int}")] | |||||
public void Put(int id, [FromBody]string value) | |||||
{ | |||||
} | |||||
[HttpDelete("{id:int}")] | |||||
public void Delete(int id) | |||||
{ | |||||
} | |||||
} | |||||
} |
@ -0,0 +1,13 @@ | |||||
namespace Microsoft.eShopOnContainers.Services.Marketing.API.Controllers | |||||
{ | |||||
using Microsoft.AspNetCore.Mvc; | |||||
// GET: /<controller>/ | |||||
public class HomeController : Controller | |||||
{ | |||||
public IActionResult Index() | |||||
{ | |||||
return new RedirectResult("~/swagger"); | |||||
} | |||||
} | |||||
} |
@ -0,0 +1,6 @@ | |||||
FROM microsoft/aspnetcore:1.1 | |||||
ARG source | |||||
WORKDIR /app | |||||
EXPOSE 80 | |||||
COPY ${source:-obj/Docker/publish} . | |||||
ENTRYPOINT ["dotnet", "Marketing.API.dll"] |
@ -0,0 +1,25 @@ | |||||
namespace Microsoft.eShopOnContainers.Services.Marketing.API.Infrastructure | |||||
{ | |||||
using Microsoft.EntityFrameworkCore; | |||||
using Microsoft.EntityFrameworkCore.Metadata.Builders; | |||||
using Microsoft.eShopOnContainers.Services.Marketing.API.Model; | |||||
public class MarketingContext : DbContext | |||||
{ | |||||
public MarketingContext(DbContextOptions options) : base(options) | |||||
{ | |||||
} | |||||
public DbSet<Campaing> Campaings { get; set; } | |||||
protected override void OnModelCreating(ModelBuilder builder) | |||||
{ | |||||
builder.Entity<Campaing>(ConfigureCampaings); | |||||
} | |||||
void ConfigureCampaings(EntityTypeBuilder<Campaing> builder) | |||||
{ | |||||
} | |||||
} | |||||
} |
@ -0,0 +1,20 @@ | |||||
namespace Microsoft.eShopOnContainers.Services.Marketing.API.Infrastructure | |||||
{ | |||||
using Microsoft.AspNetCore.Builder; | |||||
using Microsoft.EntityFrameworkCore; | |||||
using Microsoft.Extensions.Logging; | |||||
using System.Threading.Tasks; | |||||
public class MarketingContextSeed | |||||
{ | |||||
public static async Task SeedAsync(IApplicationBuilder applicationBuilder, ILoggerFactory loggerFactory, int? retry = 0) | |||||
{ | |||||
var context = (MarketingContext)applicationBuilder | |||||
.ApplicationServices.GetService(typeof(MarketingContext)); | |||||
context.Database.Migrate(); | |||||
//TODO: add model seeding | |||||
} | |||||
} | |||||
} |
@ -0,0 +1,56 @@ | |||||
<Project Sdk="Microsoft.NET.Sdk.Web"> | |||||
<PropertyGroup> | |||||
<TargetFramework>netcoreapp1.1</TargetFramework> | |||||
<DockerComposeProjectPath>..\..\..\..\docker-compose.dcproj</DockerComposeProjectPath> | |||||
<RootNamespace>Microsoft.eShopOnContainers.Services.Marketing.API</RootNamespace> | |||||
<PackageTargetFallback>portable-net45+win8</PackageTargetFallback> | |||||
<UserSecretsId>aspnet-TestApp-ce941b30-19cf-4972-b34f-d03f2e7976ed</UserSecretsId> | |||||
</PropertyGroup> | |||||
<ItemGroup> | |||||
<Folder Include="IntegrationEvents\EventHandling\" /> | |||||
<Folder Include="IntegrationEvents\Events\" /> | |||||
<Folder Include="wwwroot\" /> | |||||
</ItemGroup> | |||||
<ItemGroup> | |||||
<PackageReference Include="IdentityServer4.AccessTokenValidation" Version="1.2.0" /> | |||||
<PackageReference Include="Microsoft.ApplicationInsights.AspNetCore" Version="2.0.0" /> | |||||
<PackageReference Include="Microsoft.AspNetCore" Version="1.1.2" /> | |||||
<PackageReference Include="Microsoft.AspNetCore.Mvc" Version="1.1.3" /> | |||||
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="1.1.2" /> | |||||
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="1.1.2" /> | |||||
<PackageReference Include="Microsoft.EntityFrameworkCore.Relational" Version="1.1.2" /> | |||||
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="1.1.2" /> | |||||
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer.Design" Version="1.1.2" /> | |||||
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="1.1.1" /> | |||||
<PackageReference Include="Microsoft.Extensions.Configuration.EnvironmentVariables" Version="1.1.2" /> | |||||
<PackageReference Include="Microsoft.Extensions.Configuration.UserSecrets" Version="1.1.2" /> | |||||
<PackageReference Include="Microsoft.Extensions.Logging.Debug" Version="1.1.2" /> | |||||
<PackageReference Include="Microsoft.Extensions.Options" Version="1.1.2" /> | |||||
<PackageReference Include="Microsoft.Extensions.Options.ConfigurationExtensions" Version="1.1.2" /> | |||||
<PackageReference Include="Swashbuckle.AspNetCore" Version="1.0.0" /><PackageReference Include="IdentityServer4.AccessTokenValidation" Version="1.2.0" /> | |||||
<PackageReference Include="Microsoft.ApplicationInsights.AspNetCore" Version="2.0.0" /> | |||||
<PackageReference Include="Microsoft.AspNetCore" Version="1.1.2" /> | |||||
<PackageReference Include="Microsoft.AspNetCore.Mvc" Version="1.1.3" /> | |||||
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="1.1.2" /> | |||||
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="1.1.2" /> | |||||
<PackageReference Include="Microsoft.EntityFrameworkCore.Relational" Version="1.1.2" /> | |||||
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="1.1.2" /> | |||||
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer.Design" Version="1.1.2" /> | |||||
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="1.1.1" /> | |||||
<PackageReference Include="Microsoft.Extensions.Configuration.EnvironmentVariables" Version="1.1.2" /> | |||||
<PackageReference Include="Microsoft.Extensions.Configuration.UserSecrets" Version="2.0.0-preview1-final" /> | |||||
<PackageReference Include="Microsoft.Extensions.Logging.Debug" Version="1.1.2" /> | |||||
<PackageReference Include="Microsoft.Extensions.Options" Version="1.1.2" /> | |||||
<PackageReference Include="Microsoft.Extensions.Options.ConfigurationExtensions" Version="1.1.2" /> | |||||
<PackageReference Include="Swashbuckle.AspNetCore" Version="1.0.0" /> | |||||
</ItemGroup> | |||||
<ItemGroup> | |||||
<DotNetCliToolReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Tools" Version="1.0.1" /> | |||||
</ItemGroup> | |||||
<ItemGroup> | |||||
<DotNetCliToolReference Include="Microsoft.EntityFrameworkCore.Tools.DotNet" Version="1.0.0" /> | |||||
</ItemGroup> | |||||
</Project> |
@ -0,0 +1,7 @@ | |||||
namespace Microsoft.eShopOnContainers.Services.Marketing.API | |||||
{ | |||||
public class MarketingSettings | |||||
{ | |||||
public string ConnectionString { get; set; } | |||||
} | |||||
} |
@ -0,0 +1,7 @@ | |||||
namespace Microsoft.eShopOnContainers.Services.Marketing.API.Model | |||||
{ | |||||
public class Campaing | |||||
{ | |||||
//TODO: Add Campaing properties | |||||
} | |||||
} |
@ -0,0 +1,21 @@ | |||||
namespace Microsoft.eShopOnContainers.Services.Marketing.API | |||||
{ | |||||
using System.IO; | |||||
using Microsoft.AspNetCore.Builder; | |||||
using Microsoft.AspNetCore.Hosting; | |||||
public class Program | |||||
{ | |||||
public static void Main(string[] args) | |||||
{ | |||||
var host = new WebHostBuilder() | |||||
.UseKestrel() | |||||
.UseContentRoot(Directory.GetCurrentDirectory()) | |||||
.UseStartup<Startup>() | |||||
.UseApplicationInsights() | |||||
.Build(); | |||||
host.Run(); | |||||
} | |||||
} | |||||
} |
@ -0,0 +1,29 @@ | |||||
{ | |||||
"iisSettings": { | |||||
"windowsAuthentication": false, | |||||
"anonymousAuthentication": true, | |||||
"iisExpress": { | |||||
"applicationUrl": "http://localhost:52058/", | |||||
"sslPort": 0 | |||||
} | |||||
}, | |||||
"profiles": { | |||||
"IIS Express": { | |||||
"commandName": "IISExpress", | |||||
"launchBrowser": true, | |||||
"launchUrl": "api/values", | |||||
"environmentVariables": { | |||||
"ASPNETCORE_ENVIRONMENT": "Development" | |||||
} | |||||
}, | |||||
"Marketing.API": { | |||||
"commandName": "Project", | |||||
"launchBrowser": true, | |||||
"launchUrl": "api/values", | |||||
"environmentVariables": { | |||||
"ASPNETCORE_ENVIRONMENT": "Development" | |||||
}, | |||||
"applicationUrl": "http://localhost:52059" | |||||
} | |||||
} | |||||
} |
@ -0,0 +1,125 @@ | |||||
namespace Microsoft.eShopOnContainers.Services.Marketing.API | |||||
{ | |||||
using Microsoft.AspNetCore.Builder; | |||||
using Microsoft.AspNetCore.Hosting; | |||||
using Microsoft.EntityFrameworkCore.Infrastructure; | |||||
using Microsoft.EntityFrameworkCore; | |||||
using Microsoft.eShopOnContainers.Services.Marketing.API.Infrastructure; | |||||
using Microsoft.Extensions.Configuration; | |||||
using Microsoft.Extensions.DependencyInjection; | |||||
using Microsoft.Extensions.Logging; | |||||
using System.Reflection; | |||||
using System; | |||||
public class Startup | |||||
{ | |||||
public Startup(IHostingEnvironment env) | |||||
{ | |||||
var builder = new ConfigurationBuilder() | |||||
.SetBasePath(env.ContentRootPath) | |||||
.AddJsonFile("appsettings.json", optional: false, reloadOnChange: true) | |||||
.AddJsonFile($"appsettings.{env.EnvironmentName}.json", optional: true) | |||||
.AddEnvironmentVariables(); | |||||
if (env.IsDevelopment()) | |||||
{ | |||||
builder.AddUserSecrets(typeof(Startup).GetTypeInfo().Assembly); | |||||
} | |||||
builder.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 void ConfigureServices(IServiceCollection services) | |||||
{ | |||||
//services.AddHealthChecks(checks => | |||||
//{ | |||||
// var minutes = 1; | |||||
// if (int.TryParse(Configuration["HealthCheck:Timeout"], out var minutesParsed)) | |||||
// { | |||||
// minutes = minutesParsed; | |||||
// } | |||||
// checks.AddSqlCheck("MarketingDb", Configuration["ConnectionString"], TimeSpan.FromMinutes(minutes)); | |||||
//}); | |||||
// Add framework services. | |||||
services.AddMvc(); | |||||
services.AddDbContext<MarketingContext>(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: 5, 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 | |||||
}); | |||||
// Add framework services. | |||||
services.AddSwaggerGen(options => | |||||
{ | |||||
options.DescribeAllEnumsAsStrings(); | |||||
options.SwaggerDoc("v1", new Swashbuckle.AspNetCore.Swagger.Info | |||||
{ | |||||
Title = "Marketing HTTP API", | |||||
Version = "v1", | |||||
Description = "The Marketing Service HTTP API", | |||||
TermsOfService = "Terms Of Service" | |||||
}); | |||||
}); | |||||
services.AddCors(options => | |||||
{ | |||||
options.AddPolicy("CorsPolicy", | |||||
builder => builder.AllowAnyOrigin() | |||||
.AllowAnyMethod() | |||||
.AllowAnyHeader() | |||||
.AllowCredentials()); | |||||
}); | |||||
} | |||||
// 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(); | |||||
app.UseCors("CorsPolicy"); | |||||
ConfigureAuth(app); | |||||
app.UseMvcWithDefaultRoute(); | |||||
app.UseSwagger() | |||||
.UseSwaggerUI(c => | |||||
{ | |||||
c.SwaggerEndpoint("/swagger/v1/swagger.json", "My API V1"); | |||||
}); | |||||
//MarketingContextSeed.SeedAsync(app, loggerFactory) | |||||
// .Wait(); | |||||
} | |||||
protected virtual void ConfigureAuth(IApplicationBuilder app) | |||||
{ | |||||
var identityUrl = Configuration.GetValue<string>("IdentityUrl"); | |||||
app.UseIdentityServerAuthentication(new IdentityServerAuthenticationOptions | |||||
{ | |||||
Authority = identityUrl.ToString(), | |||||
ApiName = "marketing", | |||||
RequireHttpsMetadata = false | |||||
}); | |||||
} | |||||
} | |||||
} |
@ -0,0 +1,10 @@ | |||||
{ | |||||
"Logging": { | |||||
"IncludeScopes": false, | |||||
"LogLevel": { | |||||
"Default": "Debug", | |||||
"System": "Information", | |||||
"Microsoft": "Information" | |||||
} | |||||
} | |||||
} |
@ -0,0 +1,10 @@ | |||||
{ | |||||
"Logging": { | |||||
"IncludeScopes": false, | |||||
"LogLevel": { | |||||
"Default": "Warning" | |||||
} | |||||
}, | |||||
"ConnectionString": "127.0.0.1", | |||||
"IdentityUrl": "http://localhost:5105" | |||||
} |