Browse Source

Removed hardcoded addresses for persisted picture uris

pull/73/head
dsanz 8 years ago
parent
commit
0716bff126
7 changed files with 41 additions and 62 deletions
  1. +1
    -0
      src/Web/WebMonolithic/docker-compose.override.yml
  2. +7
    -0
      src/Web/WebMonolithic/eShopWeb/CatalogSettings.cs
  3. +12
    -12
      src/Web/WebMonolithic/eShopWeb/Infrastructure/CatalogContextSeed.cs
  4. +0
    -49
      src/Web/WebMonolithic/eShopWeb/ScaffoldingReadMe.txt
  5. +19
    -1
      src/Web/WebMonolithic/eShopWeb/Services/CatalogService.cs
  6. +1
    -0
      src/Web/WebMonolithic/eShopWeb/Startup.cs
  7. +1
    -0
      src/Web/WebMonolithic/eShopWeb/appsettings.json

+ 1
- 0
src/Web/WebMonolithic/docker-compose.override.yml View File

@ -5,6 +5,7 @@ services:
environment:
- ASPNETCORE_ENVIRONMENT=Development
- ConnectionString=Server=sql.data;Database=Microsoft.eShopOnContainers.Services.CatalogDb;User Id=sa;Password=Pass@word
- CatalogBaseUrl=http://localhost:5106
ports:
- "5106:5106"


+ 7
- 0
src/Web/WebMonolithic/eShopWeb/CatalogSettings.cs View File

@ -0,0 +1,7 @@
namespace eShopWeb
{
public class CatalogSettings
{
public string CatalogBaseUrl { get; set; }
}
}

+ 12
- 12
src/Web/WebMonolithic/eShopWeb/Infrastructure/CatalogContextSeed.cs View File

@ -85,18 +85,18 @@
{
return new List<CatalogItem>()
{
new CatalogItem() { CatalogTypeId=2,CatalogBrandId=2, Description = ".NET Bot Black Sweatshirt", Name = ".NET Bot Black Sweatshirt", Price = 19.5M, PictureUri = "http://localhost:5106/catalog/pic/1" },
new CatalogItem() { CatalogTypeId=1,CatalogBrandId=2, Description = ".NET Black & White Mug", Name = ".NET Black & White Mug", Price= 8.50M, PictureUri = "http://localhost:5106/catalog/pic/2" },
new CatalogItem() { CatalogTypeId=2,CatalogBrandId=5, Description = "Prism White T-Shirt", Name = "Prism White T-Shirt", Price = 12, PictureUri = "http://localhost:5106/catalog/pic/3" },
new CatalogItem() { CatalogTypeId=2,CatalogBrandId=2, Description = ".NET Foundation Sweatshirt", Name = ".NET Foundation Sweatshirt", Price = 12, PictureUri = "http://localhost:5106/catalog/pic/4" },
new CatalogItem() { CatalogTypeId=3,CatalogBrandId=5, Description = "Roslyn Red Sheet", Name = "Roslyn Red Sheet", Price = 8.5M, PictureUri = "http://localhost:5106/catalog/pic/5" },
new CatalogItem() { CatalogTypeId=2,CatalogBrandId=2, Description = ".NET Blue Sweatshirt", Name = ".NET Blue Sweatshirt", Price = 12, PictureUri = "http://localhost:5106/catalog/pic/6" },
new CatalogItem() { CatalogTypeId=2,CatalogBrandId=5, Description = "Roslyn Red T-Shirt", Name = "Roslyn Red T-Shirt", Price = 12, PictureUri = "http://localhost:5106/catalog/pic/7" },
new CatalogItem() { CatalogTypeId=2,CatalogBrandId=5, Description = "Kudu Purple Sweatshirt", Name = "Kudu Purple Sweatshirt", Price = 8.5M, PictureUri = "http://localhost:5106/catalog/pic/8" },
new CatalogItem() { CatalogTypeId=1,CatalogBrandId=5, Description = "Cup<T> White Mug", Name = "Cup<T> White Mug", Price = 12, PictureUri = "http://localhost:5106/catalog/pic/9" },
new CatalogItem() { CatalogTypeId=3,CatalogBrandId=2, Description = ".NET Foundation Sheet", Name = ".NET Foundation Sheet", Price = 12, PictureUri = "http://localhost:5106/catalog/pic/10" },
new CatalogItem() { CatalogTypeId=3,CatalogBrandId=2, Description = "Cup<T> Sheet", Name = "Cup<T> Sheet", Price = 8.5M, PictureUri = "http://localhost:5106/catalog/pic/11" },
new CatalogItem() { CatalogTypeId=2,CatalogBrandId=5, Description = "Prism White TShirt", Name = "Prism White TShirt", Price = 12, PictureUri = "http://localhost:5106/catalog/pic/12" }
new CatalogItem() { CatalogTypeId=2,CatalogBrandId=2, Description = ".NET Bot Black Sweatshirt", Name = ".NET Bot Black Sweatshirt", Price = 19.5M, PictureUri = "http://catalogbaseurltobereplaced/catalog/pic/1" },
new CatalogItem() { CatalogTypeId=1,CatalogBrandId=2, Description = ".NET Black & White Mug", Name = ".NET Black & White Mug", Price= 8.50M, PictureUri = "http://catalogbaseurltobereplaced/catalog/pic/2" },
new CatalogItem() { CatalogTypeId=2,CatalogBrandId=5, Description = "Prism White T-Shirt", Name = "Prism White T-Shirt", Price = 12, PictureUri = "http://catalogbaseurltobereplaced/catalog/pic/3" },
new CatalogItem() { CatalogTypeId=2,CatalogBrandId=2, Description = ".NET Foundation Sweatshirt", Name = ".NET Foundation Sweatshirt", Price = 12, PictureUri = "http://catalogbaseurltobereplaced/catalog/pic/4" },
new CatalogItem() { CatalogTypeId=3,CatalogBrandId=5, Description = "Roslyn Red Sheet", Name = "Roslyn Red Sheet", Price = 8.5M, PictureUri = "http://catalogbaseurltobereplaced/catalog/pic/5" },
new CatalogItem() { CatalogTypeId=2,CatalogBrandId=2, Description = ".NET Blue Sweatshirt", Name = ".NET Blue Sweatshirt", Price = 12, PictureUri = "http://catalogbaseurltobereplaced/catalog/pic/6" },
new CatalogItem() { CatalogTypeId=2,CatalogBrandId=5, Description = "Roslyn Red T-Shirt", Name = "Roslyn Red T-Shirt", Price = 12, PictureUri = "http://catalogbaseurltobereplaced/catalog/pic/7" },
new CatalogItem() { CatalogTypeId=2,CatalogBrandId=5, Description = "Kudu Purple Sweatshirt", Name = "Kudu Purple Sweatshirt", Price = 8.5M, PictureUri = "http://catalogbaseurltobereplaced/catalog/pic/8" },
new CatalogItem() { CatalogTypeId=1,CatalogBrandId=5, Description = "Cup<T> White Mug", Name = "Cup<T> White Mug", Price = 12, PictureUri = "http://catalogbaseurltobereplaced/catalog/pic/9" },
new CatalogItem() { CatalogTypeId=3,CatalogBrandId=2, Description = ".NET Foundation Sheet", Name = ".NET Foundation Sheet", Price = 12, PictureUri = "http://catalogbaseurltobereplaced/catalog/pic/10" },
new CatalogItem() { CatalogTypeId=3,CatalogBrandId=2, Description = "Cup<T> Sheet", Name = "Cup<T> Sheet", Price = 8.5M, PictureUri = "http://catalogbaseurltobereplaced/catalog/pic/11" },
new CatalogItem() { CatalogTypeId=2,CatalogBrandId=5, Description = "Prism White TShirt", Name = "Prism White TShirt", Price = 12, PictureUri = "http://catalogbaseurltobereplaced/catalog/pic/12" }
};
}
}


+ 0
- 49
src/Web/WebMonolithic/eShopWeb/ScaffoldingReadMe.txt View File

@ -1,49 +0,0 @@

ASP.NET MVC core dependencies have been added to the project.
However you may still need to do make changes to your project.
1. Suggested changes to Startup class:
1.1 Add a constructor:
public IConfigurationRoot Configuration { get; }
public Startup(IHostingEnvironment env)
{
var builder = new ConfigurationBuilder()
.SetBasePath(env.ContentRootPath)
.AddJsonFile("appsettings.json", optional: true, reloadOnChange: true)
.AddJsonFile($"appsettings.{env.EnvironmentName}.json", optional: true)
.AddEnvironmentVariables();
Configuration = builder.Build();
}
1.2 Add MVC services:
public void ConfigureServices(IServiceCollection services)
{
// Add framework services.
services.AddMvc();
}
1.3 Configure web app to use use Configuration and use MVC routing:
public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory)
{
loggerFactory.AddConsole(Configuration.GetSection("Logging"));
loggerFactory.AddDebug();
if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
}
else
{
app.UseExceptionHandler("/Home/Error");
}
app.UseStaticFiles();
app.UseMvc(routes =>
{
routes.MapRoute(
name: "default",
template: "{controller=Home}/{action=Index}/{id?}");
});
}

+ 19
- 1
src/Web/WebMonolithic/eShopWeb/Services/CatalogService.cs View File

@ -6,15 +6,20 @@ using eShopWeb.Models;
using Microsoft.AspNetCore.Mvc.Rendering;
using eShopWeb.Infrastructure;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Options;
using Microsoft.Extensions.Configuration;
namespace eShopWeb.Services
{
public class CatalogService : ICatalogService
{
private readonly CatalogContext _context;
public CatalogService(CatalogContext context)
private readonly IOptionsSnapshot<CatalogSettings> _settings;
public CatalogService(CatalogContext context, IOptionsSnapshot<CatalogSettings> settings)
{
_context = context;
_settings = settings;
}
public async Task<Catalog> GetCatalogItems(int pageIndex, int itemsPage, int? brandId, int? typeId)
@ -39,6 +44,8 @@ namespace eShopWeb.Services
.Take(itemsPage)
.ToListAsync();
itemsOnPage = ComposePicUri(itemsOnPage);
return new Catalog() { Data = itemsOnPage, PageIndex = pageIndex, Count = (int)totalItems };
}
@ -67,5 +74,16 @@ namespace eShopWeb.Services
return items;
}
private List<CatalogItem> ComposePicUri(List<CatalogItem> items)
{
var baseUri = _settings.Value.CatalogBaseUrl;
items.ForEach(x =>
{
x.PictureUri = x.PictureUri.Replace("http://catalogbaseurltobereplaced", baseUri);
});
return items;
}
}
}

+ 1
- 0
src/Web/WebMonolithic/eShopWeb/Startup.cs View File

@ -46,6 +46,7 @@ namespace eShopWeb
});
services.AddTransient<ICatalogService, CatalogService>();
services.Configure<CatalogSettings>(Configuration);
services.AddMvc();
}


+ 1
- 0
src/Web/WebMonolithic/eShopWeb/appsettings.json View File

@ -1,5 +1,6 @@
{
"ConnectionString": "Server=tcp:127.0.0.1,5433;Initial Catalog=Microsoft.eShopOnContainers.Services.CatalogDb;User Id=sa;Password=Pass@word",
"CatalogBaseUrl": "http://localhost:5106",
"Logging": {
"IncludeScopes": false,
"LogLevel": {


Loading…
Cancel
Save