This solution should help me explain my desire
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.AspNetCore.Mvc.Filters;
|
||||
using RepositoryLibrary;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
@@ -10,10 +11,21 @@ namespace WebMVC.Controllers
|
||||
{
|
||||
public class ApiController : Controller
|
||||
{
|
||||
private readonly IRepository _repository;
|
||||
public ApiController(IRepository repository)
|
||||
{
|
||||
_repository = repository;
|
||||
}
|
||||
public override void OnActionExecuted(ActionExecutedContext context)
|
||||
{
|
||||
// This is where I capture the error from the ApiService
|
||||
// This is where I capture the error from when calling the ApiService
|
||||
base.OnActionExecuted(context);
|
||||
}
|
||||
|
||||
public async Task<IActionResult> Lookup()
|
||||
{
|
||||
var lookup = await _repository.Lookup();
|
||||
return Ok(lookup);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,6 +5,7 @@ using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using RepositoryLibrary;
|
||||
using WebMVC.Models;
|
||||
|
||||
namespace WebMVC.Controllers
|
||||
@@ -12,10 +13,12 @@ namespace WebMVC.Controllers
|
||||
public class HomeController : Controller
|
||||
{
|
||||
private readonly ILogger<HomeController> _logger;
|
||||
private readonly IRepository _repository;
|
||||
|
||||
public HomeController(ILogger<HomeController> logger)
|
||||
public HomeController(ILogger<HomeController> logger, IRepository repository)
|
||||
{
|
||||
_logger = logger;
|
||||
_repository = repository;
|
||||
}
|
||||
|
||||
public IActionResult Index()
|
||||
@@ -23,8 +26,13 @@ namespace WebMVC.Controllers
|
||||
return View();
|
||||
}
|
||||
|
||||
public IActionResult Privacy()
|
||||
public async Task<IActionResult> Privacy()
|
||||
{
|
||||
// To get this working, I have make a call here in the Privacy page.
|
||||
// Making the call in the Home/Index page was always returning a 404 Not Found.
|
||||
// The second project was not starting quickly enough.
|
||||
|
||||
var lookup = await _repository.Lookup();
|
||||
return View();
|
||||
}
|
||||
|
||||
|
||||
@@ -7,6 +7,7 @@ using Microsoft.AspNetCore.Hosting;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.Extensions.Hosting;
|
||||
using RepositoryLibrary;
|
||||
|
||||
namespace WebMVC
|
||||
{
|
||||
@@ -19,13 +20,19 @@ namespace WebMVC
|
||||
|
||||
public IConfiguration Configuration { get; }
|
||||
|
||||
// This method gets called by the runtime. Use this method to add services to the container.
|
||||
public void ConfigureServices(IServiceCollection services)
|
||||
{
|
||||
services.AddControllersWithViews();
|
||||
if (false)
|
||||
{
|
||||
services.AddScoped<IRepository, LocalRepository>();
|
||||
}
|
||||
else
|
||||
{
|
||||
services.AddScoped<IRepository, HostedRepository>();
|
||||
}
|
||||
}
|
||||
|
||||
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
|
||||
public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
|
||||
{
|
||||
if (env.IsDevelopment())
|
||||
@@ -39,7 +46,21 @@ namespace WebMVC
|
||||
app.UseStaticFiles();
|
||||
|
||||
app.UseRouting();
|
||||
|
||||
app.Use(async (context, next) =>
|
||||
{
|
||||
try
|
||||
{
|
||||
await next();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
// Here I want to log the exception with the StackTrace.
|
||||
// The StackTrace when local is what I want
|
||||
// The StackTrace when Hosted is only to the Hosted. I'd
|
||||
// like to see the StackTrace returned from ApiService.
|
||||
return;
|
||||
}
|
||||
});
|
||||
app.UseAuthorization();
|
||||
|
||||
app.UseEndpoints(endpoints =>
|
||||
|
||||
@@ -4,4 +4,9 @@
|
||||
<TargetFramework>netcoreapp3.1</TargetFramework>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\RepositoryLibrary\RepositoryLibrary.csproj" />
|
||||
<ProjectReference Include="..\SharedLibrary\SharedLibrary.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
|
||||
Reference in New Issue
Block a user