Skip to content

Commit 3f81291

Browse files
committed
Upgraded to ABP v0.9.6.
1 parent 3cd0f2b commit 3f81291

File tree

9 files changed

+108
-64
lines changed

9 files changed

+108
-64
lines changed

src/AbpCompanyName.AbpProjectName.Application/project.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"version": "1.0.0.0-*",
33

44
"dependencies": {
5-
"Abp.AutoMapper": "0.9.5",
5+
"Abp.AutoMapper": "0.9.6",
66
"AbpCompanyName.AbpProjectName.Core": "1.0.0.0-*"
77
},
88

src/AbpCompanyName.AbpProjectName.Core/project.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"version": "1.0.0.0-*",
33

44
"dependencies": {
5-
"Abp": "0.9.5"
5+
"Abp": "0.9.6"
66
},
77

88
"frameworks": {

src/AbpCompanyName.AbpProjectName.EntityFrameworkCore/project.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"version": "1.0.0.0-*",
33

44
"dependencies": {
5-
"Abp.EntityFrameworkCore": "0.9.5",
5+
"Abp.EntityFrameworkCore": "0.9.6",
66
"AbpCompanyName.AbpProjectName.Core": "1.0.0.0-*",
77
"Microsoft.EntityFrameworkCore.SqlServer": "1.0.0-rc2-final",
88
"Microsoft.EntityFrameworkCore.Tools": {
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
using System;
2+
using Abp.AspNetCore.Mvc.Controllers;
3+
using Abp.Web.Models;
4+
using Abp.Web.Mvc.Models;
5+
using Microsoft.AspNetCore.Diagnostics;
6+
using Microsoft.AspNetCore.Mvc;
7+
8+
namespace AbpCompanyName.AbpProjectName.Web.Controllers
9+
{
10+
public class ErrorController : AbpController
11+
{
12+
private readonly IErrorInfoBuilder _errorInfoBuilder;
13+
14+
public ErrorController(IErrorInfoBuilder errorInfoBuilder)
15+
{
16+
_errorInfoBuilder = errorInfoBuilder;
17+
}
18+
19+
public ActionResult Index()
20+
{
21+
var exHandlerFeature = HttpContext.Features.Get<IExceptionHandlerFeature>();
22+
23+
var exception = exHandlerFeature != null
24+
? exHandlerFeature.Error
25+
: new Exception("Unhandled exception!");
26+
27+
return View(
28+
"Error",
29+
new ErrorViewModel(
30+
_errorInfoBuilder.BuildForException(exception),
31+
exception
32+
)
33+
);
34+
}
35+
}
36+
}

src/AbpCompanyName.AbpProjectName.Web/Controllers/HomeController.cs

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using System.Threading.Tasks;
22
using Abp.AspNetCore.Mvc.Controllers;
3+
using Abp.UI;
34
using AbpCompanyName.AbpProjectName.Products;
45
using Microsoft.AspNetCore.Mvc;
56

@@ -14,10 +15,20 @@ public HomeController(IProductAppService productAppService)
1415
_productAppService = productAppService;
1516
}
1617

17-
public async Task<IActionResult> Index()
18+
public async Task<ActionResult> Index()
1819
{
1920
var model = await _productAppService.GetAllProducts();
2021
return View(model);
2122
}
23+
24+
public ActionResult Exception1()
25+
{
26+
throw new UserFriendlyException("Test User Friendly Exception", "This is a user friendly exception directly shown to the user.");
27+
}
28+
29+
public JsonResult Exception2()
30+
{
31+
throw new UserFriendlyException("Test User Friendly Exception", "This is a user friendly exception directly shown to the user.");
32+
}
2233
}
2334
}

src/AbpCompanyName.AbpProjectName.Web/Startup.cs

Lines changed: 19 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,22 @@
11
using System;
22
using Abp.AspNetCore;
3-
using Abp.AspNetCore.Mvc.Auditing;
4-
using Abp.AspNetCore.Mvc.Authorization;
5-
using Abp.AspNetCore.Mvc.ExceptionHandling;
6-
using Abp.AspNetCore.Mvc.Results;
7-
using Abp.AspNetCore.Mvc.Validation;
8-
using Abp.Configuration.Startup;
93
using AbpCompanyName.AbpProjectName.EntityFrameworkCore;
104
using Castle.Facilities.Logging;
11-
using Castle.LoggingFacility.MsLogging;
125
using Microsoft.AspNetCore.Builder;
136
using Microsoft.AspNetCore.Hosting;
14-
using Microsoft.AspNetCore.Http;
15-
using Microsoft.AspNetCore.Mvc.Formatters;
16-
using Microsoft.AspNetCore.Mvc.Infrastructure;
177
using Microsoft.EntityFrameworkCore;
188
using Microsoft.Extensions.Configuration;
199
using Microsoft.Extensions.DependencyInjection;
20-
using Microsoft.Extensions.DependencyInjection.Extensions;
2110
using Microsoft.Extensions.Logging;
22-
using Newtonsoft.Json;
23-
using Newtonsoft.Json.Serialization;
11+
using Abp.AspNetCore.Mvc;
2412

2513
namespace AbpCompanyName.AbpProjectName.Web
2614
{
27-
public class Startup : AbpStartup
15+
public class Startup
2816
{
2917
public IConfigurationRoot Configuration { get; }
3018

3119
public Startup(IHostingEnvironment env)
32-
: base(env)
3320
{
3421
var builder = new ConfigurationBuilder()
3522
.SetBasePath(env.ContentRootPath)
@@ -39,60 +26,40 @@ public Startup(IHostingEnvironment env)
3926
Configuration = builder.Build();
4027
}
4128

42-
protected override void InitializeAbp()
29+
public IServiceProvider ConfigureServices(IServiceCollection services)
4330
{
44-
AbpBootstrapper.IocManager.IocContainer.AddFacility<LoggingFacility>(
45-
f => f.UseLog4Net().WithConfig("log4net.config")
46-
);
47-
48-
base.InitializeAbp();
49-
}
50-
51-
public override IServiceProvider ConfigureServices(IServiceCollection services)
52-
{
53-
//See https://github.com/aspnet/Mvc/issues/3936 to know why we added these services.
54-
services.TryAddSingleton<IHttpContextAccessor, HttpContextAccessor>();
55-
services.TryAddSingleton<IActionContextAccessor, ActionContextAccessor>();
56-
57-
var defaultConnectionString = Configuration.GetConnectionString("Default");
58-
AbpBootstrapper.IocManager.Resolve<IAbpStartupConfiguration>().DefaultNameOrConnectionString = defaultConnectionString;
5931
services.AddDbContext<AbpProjectNameDbContext>(
60-
options => options.UseSqlServer(defaultConnectionString)
32+
options => options.UseSqlServer(Configuration.GetConnectionString("Default"))
6133
);
6234

63-
// Add framework services.
6435
services.AddMvc(options =>
6536
{
66-
options.Filters.AddService(typeof(AbpAuthorizationFilter));
67-
options.Filters.AddService(typeof(AbpAuditActionFilter));
68-
options.Filters.AddService(typeof(AbpValidationActionFilter));
69-
options.Filters.AddService(typeof(AbpExceptionFilter));
70-
options.Filters.AddService(typeof(AbpResultFilter));
71-
72-
options.OutputFormatters.Add(new JsonOutputFormatter(
73-
new JsonSerializerSettings
74-
{
75-
ContractResolver = new CamelCasePropertyNamesContractResolver()
76-
}));
77-
37+
options.AddAbp(); //Add ABP infrastructure to MVC
7838
}).AddControllersAsServices();
7939

80-
return base.ConfigureServices(services);
40+
//Configure Abp and Dependency Injection
41+
return services.AddAbp(abpBootstrapper =>
42+
{
43+
//Configure Log4Net logging
44+
abpBootstrapper.IocManager.IocContainer.AddFacility<LoggingFacility>(
45+
f => f.UseLog4Net().WithConfig("log4net.config")
46+
);
47+
});
8148
}
8249

83-
public override void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory)
50+
public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory)
8451
{
85-
base.Configure(app, env, loggerFactory);
86-
87-
loggerFactory.AddConsole(Configuration.GetSection("Logging"));
88-
loggerFactory.AddDebug();
89-
loggerFactory.AddCastleLogger(AbpBootstrapper.IocManager.Resolve<Castle.Core.Logging.ILoggerFactory>());
52+
app.UseAbp(); //Initializes ABP framework.
9053

9154
if (env.IsDevelopment())
9255
{
9356
app.UseDeveloperExceptionPage();
9457
app.UseDatabaseErrorPage();
9558
}
59+
else
60+
{
61+
app.UseExceptionHandler("/Error");
62+
}
9663

9764
app.UseStaticFiles();
9865

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
@using Abp.Collections.Extensions
2+
@model Abp.Web.Mvc.Models.ErrorViewModel
3+
<div class="row">
4+
<section class="col-lg-12">
5+
<div class="panel panel-warning">
6+
<div class="panel-heading">
7+
<h3 class="panel-title">@Model.ErrorInfo.Message</h3>
8+
</div>
9+
<div class="panel-body">
10+
<p>
11+
@(!string.IsNullOrEmpty(Model.ErrorInfo.Details) ? Model.ErrorInfo.Details : Model.ErrorInfo.Message)
12+
</p>
13+
@* Show validation errors *@
14+
@if (!Model.ErrorInfo.ValidationErrors.IsNullOrEmpty())
15+
{
16+
<ul>
17+
@foreach (var validationError in Model.ErrorInfo.ValidationErrors)
18+
{
19+
<li>
20+
@validationError.Message
21+
@if (validationError.Members != null && validationError.Members.Any())
22+
{
23+
<text>(@string.Join(", ", validationError.Members))</text>
24+
}
25+
</li>
26+
}
27+
</ul>
28+
}
29+
</div>
30+
</div>
31+
</section>
32+
</div>

src/AbpCompanyName.AbpProjectName.Web/project.json

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,6 @@
1313
"Microsoft.AspNetCore.Diagnostics": "1.0.0-rc2-final",
1414
"Microsoft.AspNetCore.Diagnostics.EntityFrameworkCore": "1.0.0-rc2-final",
1515
"Microsoft.Extensions.Logging": "1.0.0-rc2-final",
16-
"Microsoft.Extensions.Logging.Console": "1.0.0-rc2-final",
17-
"Microsoft.Extensions.Logging.Debug": "1.0.0-rc2-final",
1816
"Microsoft.VisualStudio.Web.BrowserLink.Loader": "14.0.0-rc2-final",
1917
"Microsoft.VisualStudio.Web.CodeGeneration.Tools": {
2018
"version": "1.0.0-preview1-final",
@@ -32,8 +30,8 @@
3230
"Castle.Windsor-log4net": "3.3.0",
3331
"AbpCompanyName.AbpProjectName.Application": "1.0.0.0-*",
3432
"AbpCompanyName.AbpProjectName.EntityFrameworkCore": "1.0.0.0-*",
35-
"Abp.AspNetCore": "0.9.5",
36-
"Castle.LoggingFacility.MsLogging": "0.1.0"
33+
"Castle.LoggingFacility.MsLogging": "0.1.0",
34+
"Abp.AspNetCore": "0.9.6"
3735
},
3836

3937
"tools": {

test/AbpCompanyName.AbpProjectName.Tests/project.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
1-
{
1+
{
22
"version": "1.0.0.0-*",
33

44
"testRunner": "xunit",
55

66
"dependencies": {
7-
"Castle.Windsor.MsDependencyInjection": "0.1.0",
87
"Microsoft.EntityFrameworkCore.InMemory": "1.0.0-rc2-final",
98
"xunit": "2.1.0",
109
"xunit.runner.visualstudio": "2.1.0",
@@ -13,8 +12,9 @@
1312
"NSubstitute": "1.10.0",
1413
"AbpCompanyName.AbpProjectName.Application": "1.0.0.0-*",
1514
"AbpCompanyName.AbpProjectName.EntityFrameworkCore": "1.0.0.0-*",
16-
"Abp.TestBase": "0.9.5",
17-
"Shouldly": "2.8.0"
15+
"Shouldly": "2.8.0",
16+
"Abp.TestBase": "0.9.6",
17+
"Castle.Windsor.MsDependencyInjection": "0.2.0"
1818
},
1919

2020
"frameworks": {

0 commit comments

Comments
 (0)