()
30 | .Build();
31 | }
32 | }
33 |
--------------------------------------------------------------------------------
/extras/sample/AspectCore.Extensions.AspNetCore.Sample/Properties/launchSettings.json:
--------------------------------------------------------------------------------
1 | {
2 | "iisSettings": {
3 | "windowsAuthentication": false,
4 | "anonymousAuthentication": true,
5 | "iisExpress": {
6 | "applicationUrl": "http://localhost:54380/",
7 | "sslPort": 44314
8 | }
9 | },
10 | "profiles": {
11 | "IIS Express": {
12 | "commandName": "IISExpress",
13 | "launchBrowser": true,
14 | "launchUrl": "https://localhost:44314/",
15 | "environmentVariables": {
16 | "ASPNETCORE_ENVIRONMENT": "Development"
17 | }
18 | },
19 | "AspNetCore.Sample": {
20 | "commandName": "Project",
21 | "launchBrowser": true,
22 | "environmentVariables": {
23 | "ASPNETCORE_ENVIRONMENT": "Development"
24 | },
25 | "applicationUrl": "http://localhost:54381/"
26 | }
27 | }
28 | }
29 |
--------------------------------------------------------------------------------
/extras/sample/AspectCore.Extensions.AspNetCore.Sample/Services/BookService.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using AspectCore.Extensions.DataValidation;
3 | using AspNetCore.Sample.Models;
4 |
5 | namespace AspNetCore.Sample.Services
6 | {
7 | public class BookService : IBookService
8 | {
9 | public IDataState DataState { get; set; }
10 |
11 | public void Create(CreateBookDto dto)
12 | {
13 | if (string.Equals(dto?.Author, "lemon", StringComparison.Ordinal))
14 | {
15 | DataState?.Errors?.Add(new DataValidationError("Author", "lemon向阁下问好!"));
16 | }
17 | }
18 | }
19 | }
20 |
--------------------------------------------------------------------------------
/extras/sample/AspectCore.Extensions.AspNetCore.Sample/Services/EmailSender.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Threading.Tasks;
5 |
6 | namespace AspNetCore.Sample.Services
7 | {
8 | // This class is used by the application to send email for account confirmation and password reset.
9 | // For more details see https://go.microsoft.com/fwlink/?LinkID=532713
10 | public class EmailSender : IEmailSender
11 | {
12 | public Task SendEmailAsync(string email, string subject, string message)
13 | {
14 | return Task.CompletedTask;
15 | }
16 | }
17 | }
18 |
--------------------------------------------------------------------------------
/extras/sample/AspectCore.Extensions.AspNetCore.Sample/Services/IBookService.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Threading.Tasks;
5 | using AspNetCore.Sample.Models;
6 |
7 | namespace AspNetCore.Sample.Services
8 | {
9 | public interface IBookService
10 | {
11 | void Create(CreateBookDto dto);
12 | }
13 | }
14 |
--------------------------------------------------------------------------------
/extras/sample/AspectCore.Extensions.AspNetCore.Sample/Services/IEmailSender.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Threading.Tasks;
5 |
6 | namespace AspNetCore.Sample.Services
7 | {
8 | public interface IEmailSender
9 | {
10 | Task SendEmailAsync(string email, string subject, string message);
11 | }
12 | }
13 |
--------------------------------------------------------------------------------
/extras/sample/AspectCore.Extensions.AspNetCore.Sample/Views/Account/AccessDenied.cshtml:
--------------------------------------------------------------------------------
1 | @{
2 | ViewData["Title"] = "Access denied";
3 | }
4 |
5 |
9 |
--------------------------------------------------------------------------------
/extras/sample/AspectCore.Extensions.AspNetCore.Sample/Views/Account/ConfirmEmail.cshtml:
--------------------------------------------------------------------------------
1 | @{
2 | ViewData["Title"] = "Confirm email";
3 | }
4 |
5 | @ViewData["Title"]
6 |
7 |
8 | Thank you for confirming your email.
9 |
10 |
11 |
--------------------------------------------------------------------------------
/extras/sample/AspectCore.Extensions.AspNetCore.Sample/Views/Account/ForgotPassword.cshtml:
--------------------------------------------------------------------------------
1 | @model ForgotPasswordViewModel
2 | @{
3 | ViewData["Title"] = "Forgot your password?";
4 | }
5 |
6 | @ViewData["Title"]
7 | Enter your email.
8 |
9 |
22 |
23 | @section Scripts {
24 | @await Html.PartialAsync("_ValidationScriptsPartial")
25 | }
26 |
--------------------------------------------------------------------------------
/extras/sample/AspectCore.Extensions.AspNetCore.Sample/Views/Account/ForgotPasswordConfirmation.cshtml:
--------------------------------------------------------------------------------
1 | @{
2 | ViewData["Title"] = "Forgot password confirmation";
3 | }
4 |
5 | @ViewData["Title"]
6 |
7 | Please check your email to reset your password.
8 |
9 |
--------------------------------------------------------------------------------
/extras/sample/AspectCore.Extensions.AspNetCore.Sample/Views/Account/Lockout.cshtml:
--------------------------------------------------------------------------------
1 | @{
2 | ViewData["Title"] = "Locked out";
3 | }
4 |
5 |
9 |
--------------------------------------------------------------------------------
/extras/sample/AspectCore.Extensions.AspNetCore.Sample/Views/Account/LoginWithRecoveryCode.cshtml:
--------------------------------------------------------------------------------
1 | @model LoginWithRecoveryCodeViewModel
2 | @{
3 | ViewData["Title"] = "Recovery code verification";
4 | }
5 |
6 | @ViewData["Title"]
7 |
8 |
9 | You have requested to login with a recovery code. This login will not be remembered until you provide
10 | an authenticator app code at login or disable 2FA and login again.
11 |
12 |
25 |
26 | @section Scripts {
27 | @await Html.PartialAsync("_ValidationScriptsPartial")
28 | }
--------------------------------------------------------------------------------
/extras/sample/AspectCore.Extensions.AspNetCore.Sample/Views/Account/ResetPasswordConfirmation.cshtml:
--------------------------------------------------------------------------------
1 | @{
2 | ViewData["Title"] = "Reset password confirmation";
3 | }
4 |
5 | @ViewData["Title"]
6 |
7 | Your password has been reset. Please click here to log in.
8 |
9 |
--------------------------------------------------------------------------------
/extras/sample/AspectCore.Extensions.AspNetCore.Sample/Views/Account/SignedOut.cshtml:
--------------------------------------------------------------------------------
1 | @{
2 | ViewData["Title"] = "Signed out";
3 | }
4 |
5 | @ViewData["Title"]
6 |
7 | You have successfully signed out.
8 |
9 |
--------------------------------------------------------------------------------
/extras/sample/AspectCore.Extensions.AspNetCore.Sample/Views/Home/About.cshtml:
--------------------------------------------------------------------------------
1 | @{
2 | ViewData["Title"] = "About";
3 | }
4 | @ViewData["Title"]
5 | @ViewData["Message"]
6 |
7 | Use this area to provide additional information.
8 |
--------------------------------------------------------------------------------
/extras/sample/AspectCore.Extensions.AspNetCore.Sample/Views/Home/Contact.cshtml:
--------------------------------------------------------------------------------
1 | @{
2 | ViewData["Title"] = "Contact";
3 | }
4 | @ViewData["Title"]
5 | @ViewData["Message"]
6 |
7 |
8 | One Microsoft Way
9 | Redmond, WA 98052-6399
10 | P:
11 | 425.555.0100
12 |
13 |
14 |
15 | Support: Support@example.com
16 | Marketing: Marketing@example.com
17 |
18 |
--------------------------------------------------------------------------------
/extras/sample/AspectCore.Extensions.AspNetCore.Sample/Views/Manage/Disable2fa.cshtml:
--------------------------------------------------------------------------------
1 | @{
2 | ViewData["Title"] = "Disable two-factor authentication (2FA)";
3 | ViewData.AddActivePage(ManageNavPages.TwoFactorAuthentication);
4 | }
5 |
6 | @ViewData["Title"]
7 |
8 |
9 |
10 |
11 | This action only disables 2FA.
12 |
13 |
14 | Disabling 2FA does not change the keys used in authenticator apps. If you wish to change the key
15 | used in an authenticator app you should reset your
16 | authenticator keys.
17 |
18 |
19 |
20 |
21 |
24 |
25 |
--------------------------------------------------------------------------------
/extras/sample/AspectCore.Extensions.AspNetCore.Sample/Views/Manage/GenerateRecoveryCodes.cshtml:
--------------------------------------------------------------------------------
1 | @model GenerateRecoveryCodesViewModel
2 | @{
3 | ViewData["Title"] = "Recovery codes";
4 | ViewData.AddActivePage(ManageNavPages.TwoFactorAuthentication);
5 | }
6 |
7 | @ViewData["Title"]
8 |
9 |
10 |
11 | Put these codes in a safe place.
12 |
13 |
14 | If you lose your device and don't have the recovery codes you will lose access to your account.
15 |
16 |
17 |
18 |
19 | @for (var row = 0; row < Model.RecoveryCodes.Count(); row += 2)
20 | {
21 | @Model.RecoveryCodes[row]
@Model.RecoveryCodes[row + 1]
22 | }
23 |
24 |
--------------------------------------------------------------------------------
/extras/sample/AspectCore.Extensions.AspNetCore.Sample/Views/Manage/ResetAuthenticator.cshtml:
--------------------------------------------------------------------------------
1 | @{
2 | ViewData["Title"] = "Reset authenticator key";
3 | ViewData.AddActivePage(ManageNavPages.TwoFactorAuthentication);
4 | }
5 |
6 | @ViewData["Title"]
7 |
8 |
9 |
10 | If you reset your authenticator key your authenticator app will not work until you reconfigure it.
11 |
12 |
13 | This process disables 2FA until you verify your authenticator app and will also reset your 2FA recovery codes.
14 | If you do not complete your authenticator app configuration you may lose access to your account.
15 |
16 |
17 |
18 |
21 |
--------------------------------------------------------------------------------
/extras/sample/AspectCore.Extensions.AspNetCore.Sample/Views/Manage/_Layout.cshtml:
--------------------------------------------------------------------------------
1 | @{
2 | Layout = "/Views/Shared/_Layout.cshtml";
3 | }
4 |
5 | Manage your account
6 |
7 |
8 |
Change your account settings
9 |
10 |
11 |
12 | @await Html.PartialAsync("_ManageNav")
13 |
14 |
15 | @RenderBody()
16 |
17 |
18 |
19 |
20 | @section Scripts {
21 | @RenderSection("Scripts", required: false)
22 | }
23 |
24 |
--------------------------------------------------------------------------------
/extras/sample/AspectCore.Extensions.AspNetCore.Sample/Views/Manage/_ManageNav.cshtml:
--------------------------------------------------------------------------------
1 | @using AspNetCore.Sample.Views.Manage
2 | @inject SignInManager SignInManager
3 | @{
4 | var hasExternalLogins = (await SignInManager.GetExternalAuthenticationSchemesAsync()).Any();
5 | }
6 |
7 |
16 |
17 |
--------------------------------------------------------------------------------
/extras/sample/AspectCore.Extensions.AspNetCore.Sample/Views/Manage/_StatusMessage.cshtml:
--------------------------------------------------------------------------------
1 | @model string
2 |
3 | @if (!String.IsNullOrEmpty(Model))
4 | {
5 | var statusMessageClass = Model.StartsWith("Error") ? "danger" : "success";
6 |
7 |
8 | @Model
9 |
10 | }
11 |
--------------------------------------------------------------------------------
/extras/sample/AspectCore.Extensions.AspNetCore.Sample/Views/Manage/_ViewImports.cshtml:
--------------------------------------------------------------------------------
1 | @using AspNetCore.Sample.Views.Manage
2 |
--------------------------------------------------------------------------------
/extras/sample/AspectCore.Extensions.AspNetCore.Sample/Views/Shared/Error.cshtml:
--------------------------------------------------------------------------------
1 | @model ErrorViewModel
2 | @{
3 | ViewData["Title"] = "Error";
4 | }
5 |
6 | Error.
7 | An error occurred while processing your request.
8 |
9 | @if (Model.ShowRequestId)
10 | {
11 |
12 | Request ID: @Model.RequestId
13 |
14 | }
15 |
16 | Development Mode
17 |
18 | Swapping to Development environment will display more detailed information about the error that occurred.
19 |
20 |
21 | Development environment should not be enabled in deployed applications, as it can result in sensitive information from exceptions being displayed to end users. For local debugging, development environment can be enabled by setting the ASPNETCORE_ENVIRONMENT environment variable to Development, and restarting the application.
22 |
23 |
--------------------------------------------------------------------------------
/extras/sample/AspectCore.Extensions.AspNetCore.Sample/Views/Shared/_LoginPartial.cshtml:
--------------------------------------------------------------------------------
1 | @using Microsoft.AspNetCore.Identity
2 | @using AspNetCore.Sample.Models
3 |
4 | @inject SignInManager SignInManager
5 | @inject UserManager UserManager
6 |
7 | @if (SignInManager.IsSignedIn(User))
8 | {
9 |
19 | }
20 | else
21 | {
22 |
26 | }
27 |
--------------------------------------------------------------------------------
/extras/sample/AspectCore.Extensions.AspNetCore.Sample/Views/_ViewImports.cshtml:
--------------------------------------------------------------------------------
1 | @using Microsoft.AspNetCore.Identity
2 | @using AspNetCore.Sample
3 | @using AspNetCore.Sample.Models
4 | @using AspNetCore.Sample.Models.AccountViewModels
5 | @using AspNetCore.Sample.Models.ManageViewModels
6 | @addTagHelper *, Microsoft.AspNetCore.Mvc.TagHelpers
7 |
--------------------------------------------------------------------------------
/extras/sample/AspectCore.Extensions.AspNetCore.Sample/Views/_ViewStart.cshtml:
--------------------------------------------------------------------------------
1 | @{
2 | Layout = "_Layout";
3 | }
4 |
--------------------------------------------------------------------------------
/extras/sample/AspectCore.Extensions.AspNetCore.Sample/appsettings.Development.json:
--------------------------------------------------------------------------------
1 | {
2 | "Logging": {
3 | "IncludeScopes": false,
4 | "LogLevel": {
5 | "Default": "Debug",
6 | "System": "Information",
7 | "Microsoft": "Information"
8 | }
9 | }
10 | }
11 |
--------------------------------------------------------------------------------
/extras/sample/AspectCore.Extensions.AspNetCore.Sample/appsettings.json:
--------------------------------------------------------------------------------
1 | {
2 | "ConnectionStrings": {
3 | "DefaultConnection": "Server=(localdb)\\mssqllocaldb;Database=aspnet-AspNetCore.Sample-801AA809-9522-45D6-B05D-BA4E539F156C;Trusted_Connection=True;MultipleActiveResultSets=true"
4 | },
5 | "Logging": {
6 | "IncludeScopes": false,
7 | "LogLevel": {
8 | "Default": "Warning"
9 | }
10 | }
11 | }
12 |
--------------------------------------------------------------------------------
/extras/sample/AspectCore.Extensions.AspNetCore.Sample/bower.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "asp.net",
3 | "private": true,
4 | "dependencies": {
5 | "bootstrap": "3.3.7",
6 | "jquery": "2.2.0",
7 | "jquery-validation": "1.14.0",
8 | "jquery-validation-unobtrusive": "3.2.6"
9 | }
10 | }
11 |
--------------------------------------------------------------------------------
/extras/sample/AspectCore.Extensions.AspNetCore.Sample/bundleconfig.json:
--------------------------------------------------------------------------------
1 | // Configure bundling and minification for the project.
2 | // More info at https://go.microsoft.com/fwlink/?LinkId=808241
3 | [
4 | {
5 | "outputFileName": "wwwroot/css/site.min.css",
6 | // An array of relative input file paths. Globbing patterns supported
7 | "inputFiles": [
8 | "wwwroot/css/site.css"
9 | ]
10 | },
11 | {
12 | "outputFileName": "wwwroot/js/site.min.js",
13 | "inputFiles": [
14 | "wwwroot/js/site.js"
15 | ],
16 | // Optionally specify minification options
17 | "minify": {
18 | "enabled": true,
19 | "renameLocals": true
20 | },
21 | // Optionally generate .map file
22 | "sourceMap": false
23 | }
24 | ]
25 |
--------------------------------------------------------------------------------
/extras/sample/AspectCore.Extensions.AspNetCore.Sample/wwwroot/css/site.css:
--------------------------------------------------------------------------------
1 | body {
2 | padding-top: 50px;
3 | padding-bottom: 20px;
4 | }
5 |
6 | /* Wrapping element */
7 | /* Set some basic padding to keep content from hitting the edges */
8 | .body-content {
9 | padding-left: 15px;
10 | padding-right: 15px;
11 | }
12 |
13 | /* Carousel */
14 | .carousel-caption p {
15 | font-size: 20px;
16 | line-height: 1.4;
17 | }
18 |
19 | /* Make .svg files in the carousel display properly in older browsers */
20 | .carousel-inner .item img[src$=".svg"] {
21 | width: 100%;
22 | }
23 |
24 | /* QR code generator */
25 | #qrCode {
26 | margin: 15px;
27 | }
28 |
29 | /* Hide/rearrange for smaller screens */
30 | @media screen and (max-width: 767px) {
31 | /* Hide captions */
32 | .carousel-caption {
33 | display: none;
34 | }
35 | }
36 |
--------------------------------------------------------------------------------
/extras/sample/AspectCore.Extensions.AspNetCore.Sample/wwwroot/css/site.min.css:
--------------------------------------------------------------------------------
1 | body{padding-top:50px;padding-bottom:20px}.body-content{padding-left:15px;padding-right:15px}.carousel-caption p{font-size:20px;line-height:1.4}.carousel-inner .item img[src$=".svg"]{width:100%}#qrCode{margin:15px}@media screen and (max-width:767px){.carousel-caption{display:none}}
--------------------------------------------------------------------------------
/extras/sample/AspectCore.Extensions.AspNetCore.Sample/wwwroot/favicon.ico:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/AspectCore/AspectCore-Framework/97f3eb19d348054de5f9da07e05e920ddbae35e9/extras/sample/AspectCore.Extensions.AspNetCore.Sample/wwwroot/favicon.ico
--------------------------------------------------------------------------------
/extras/sample/AspectCore.Extensions.AspNetCore.Sample/wwwroot/js/site.js:
--------------------------------------------------------------------------------
1 | // Write your JavaScript code.
2 |
--------------------------------------------------------------------------------
/extras/sample/AspectCore.Extensions.AspNetCore.Sample/wwwroot/js/site.min.js:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/AspectCore/AspectCore-Framework/97f3eb19d348054de5f9da07e05e920ddbae35e9/extras/sample/AspectCore.Extensions.AspNetCore.Sample/wwwroot/js/site.min.js
--------------------------------------------------------------------------------
/extras/sample/AspectCore.Extensions.AspNetCore.Sample/wwwroot/lib/bootstrap/dist/fonts/glyphicons-halflings-regular.eot:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/AspectCore/AspectCore-Framework/97f3eb19d348054de5f9da07e05e920ddbae35e9/extras/sample/AspectCore.Extensions.AspNetCore.Sample/wwwroot/lib/bootstrap/dist/fonts/glyphicons-halflings-regular.eot
--------------------------------------------------------------------------------
/extras/sample/AspectCore.Extensions.AspNetCore.Sample/wwwroot/lib/bootstrap/dist/fonts/glyphicons-halflings-regular.ttf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/AspectCore/AspectCore-Framework/97f3eb19d348054de5f9da07e05e920ddbae35e9/extras/sample/AspectCore.Extensions.AspNetCore.Sample/wwwroot/lib/bootstrap/dist/fonts/glyphicons-halflings-regular.ttf
--------------------------------------------------------------------------------
/extras/sample/AspectCore.Extensions.AspNetCore.Sample/wwwroot/lib/bootstrap/dist/fonts/glyphicons-halflings-regular.woff:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/AspectCore/AspectCore-Framework/97f3eb19d348054de5f9da07e05e920ddbae35e9/extras/sample/AspectCore.Extensions.AspNetCore.Sample/wwwroot/lib/bootstrap/dist/fonts/glyphicons-halflings-regular.woff
--------------------------------------------------------------------------------
/extras/sample/AspectCore.Extensions.AspNetCore.Sample/wwwroot/lib/bootstrap/dist/fonts/glyphicons-halflings-regular.woff2:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/AspectCore/AspectCore-Framework/97f3eb19d348054de5f9da07e05e920ddbae35e9/extras/sample/AspectCore.Extensions.AspNetCore.Sample/wwwroot/lib/bootstrap/dist/fonts/glyphicons-halflings-regular.woff2
--------------------------------------------------------------------------------
/extras/sample/AspectCore.Extensions.AspNetCore.Sample/wwwroot/lib/bootstrap/dist/js/npm.js:
--------------------------------------------------------------------------------
1 | // This file is autogenerated via the `commonjs` Grunt task. You can require() this file in a CommonJS environment.
2 | require('../../js/transition.js')
3 | require('../../js/alert.js')
4 | require('../../js/button.js')
5 | require('../../js/carousel.js')
6 | require('../../js/collapse.js')
7 | require('../../js/dropdown.js')
8 | require('../../js/modal.js')
9 | require('../../js/tooltip.js')
10 | require('../../js/popover.js')
11 | require('../../js/scrollspy.js')
12 | require('../../js/tab.js')
13 | require('../../js/affix.js')
--------------------------------------------------------------------------------
/extras/sample/AspectCore.Extensions.AspNetCore.Sample/wwwroot/lib/jquery-validation/.bower.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "jquery-validation",
3 | "homepage": "http://jqueryvalidation.org/",
4 | "repository": {
5 | "type": "git",
6 | "url": "git://github.com/jzaefferer/jquery-validation.git"
7 | },
8 | "authors": [
9 | "Jörn Zaefferer "
10 | ],
11 | "description": "Form validation made easy",
12 | "main": "dist/jquery.validate.js",
13 | "keywords": [
14 | "forms",
15 | "validation",
16 | "validate"
17 | ],
18 | "license": "MIT",
19 | "ignore": [
20 | "**/.*",
21 | "node_modules",
22 | "bower_components",
23 | "test",
24 | "demo",
25 | "lib"
26 | ],
27 | "dependencies": {
28 | "jquery": ">= 1.7.2"
29 | },
30 | "version": "1.14.0",
31 | "_release": "1.14.0",
32 | "_resolution": {
33 | "type": "version",
34 | "tag": "1.14.0",
35 | "commit": "c1343fb9823392aa9acbe1c3ffd337b8c92fed48"
36 | },
37 | "_source": "git://github.com/jzaefferer/jquery-validation.git",
38 | "_target": ">=1.8",
39 | "_originalSource": "jquery-validation"
40 | }
--------------------------------------------------------------------------------
/extras/sample/AspectCore.Extensions.AspNetCore.Sample/wwwroot/lib/jquery/.bower.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "jquery",
3 | "main": "dist/jquery.js",
4 | "license": "MIT",
5 | "ignore": [
6 | "package.json"
7 | ],
8 | "keywords": [
9 | "jquery",
10 | "javascript",
11 | "browser",
12 | "library"
13 | ],
14 | "homepage": "https://github.com/jquery/jquery-dist",
15 | "version": "2.2.0",
16 | "_release": "2.2.0",
17 | "_resolution": {
18 | "type": "version",
19 | "tag": "2.2.0",
20 | "commit": "6fc01e29bdad0964f62ef56d01297039cdcadbe5"
21 | },
22 | "_source": "git://github.com/jquery/jquery-dist.git",
23 | "_target": "2.2.0",
24 | "_originalSource": "jquery"
25 | }
--------------------------------------------------------------------------------
/extras/sample/AspectCore.Extensions.Autofac.Sample/AspectCore.Extensions.Autofac.Sample.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | Exe
5 | netcoreapp2.0
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
--------------------------------------------------------------------------------
/extras/sample/AspectCore.Extensions.Autofac.Sample/MethodExecuteLoggerInterceptor.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Diagnostics;
4 | using System.Text;
5 | using System.Threading.Tasks;
6 | using AspectCore.DynamicProxy;
7 |
8 | namespace AspectCore.Extensions.Autofac.Sample
9 | {
10 | public class MethodExecuteLoggerInterceptor : AbstractInterceptor
11 | {
12 | public async override Task Invoke(AspectContext context, AspectDelegate next)
13 | {
14 | Stopwatch stopwatch = Stopwatch.StartNew();
15 | await next(context);
16 | stopwatch.Stop();
17 | Console.WriteLine("Executed method {0}.{1}.{2} ({3}) in {4}ms",
18 | context.ServiceMethod.DeclaringType.Namespace,
19 | context.ServiceMethod.DeclaringType.Name,
20 | context.ServiceMethod.Name,
21 | context.ServiceMethod.DeclaringType.Assembly.GetName().Name,
22 | stopwatch.ElapsedMilliseconds
23 | );
24 | }
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/extras/sample/AspectCore.Extensions.Autofac.WebSample/AspectCore.Extensions.Autofac.WebSample.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | netcoreapp2.0
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
--------------------------------------------------------------------------------
/extras/sample/AspectCore.Extensions.Autofac.WebSample/DynamicProxy/MethodExecuteLoggerInterceptor.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Diagnostics;
4 | using System.Linq;
5 | using System.Threading.Tasks;
6 | using AspectCore.DynamicProxy;
7 |
8 | namespace AspectCore.Extensions.Autofac.WebSample
9 | {
10 | public class MethodExecuteLoggerInterceptor : AbstractInterceptor
11 | {
12 | public async override Task Invoke(AspectContext context, AspectDelegate next)
13 | {
14 | Stopwatch stopwatch = Stopwatch.StartNew();
15 | await next(context);
16 | stopwatch.Stop();
17 | Console.WriteLine("Executed method {0}.{1}.{2} ({3}) in {4}ms",
18 | context.ServiceMethod.DeclaringType.Namespace,
19 | context.ServiceMethod.DeclaringType.Name,
20 | context.ServiceMethod.Name,
21 | context.ServiceMethod.DeclaringType.Assembly.GetName().Name,
22 | stopwatch.ElapsedMilliseconds
23 | );
24 | }
25 | }
26 | }
--------------------------------------------------------------------------------
/extras/sample/AspectCore.Extensions.Autofac.WebSample/Program.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.IO;
4 | using System.Linq;
5 | using System.Threading.Tasks;
6 | using Microsoft.AspNetCore;
7 | using Microsoft.AspNetCore.Hosting;
8 | using Microsoft.Extensions.Configuration;
9 | using Microsoft.Extensions.Logging;
10 |
11 | namespace AspectCore.Extensions.Autofac.WebSample
12 | {
13 | public class Program
14 | {
15 | public static void Main(string[] args)
16 | {
17 | BuildWebHost(args).Run();
18 | }
19 |
20 | public static IWebHost BuildWebHost(string[] args) =>
21 | WebHost.CreateDefaultBuilder(args)
22 | .UseStartup()
23 | .UseKestrel()
24 | .Build();
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/extras/sample/AspectCore.Extensions.Autofac.WebSample/Properties/launchSettings.json:
--------------------------------------------------------------------------------
1 | {
2 | "iisSettings": {
3 | "windowsAuthentication": false,
4 | "anonymousAuthentication": true,
5 | "iisExpress": {
6 | "applicationUrl": "http://localhost:16954/",
7 | "sslPort": 0
8 | }
9 | },
10 | "profiles": {
11 | "IIS Express": {
12 | "commandName": "IISExpress",
13 | "launchBrowser": true,
14 | "launchUrl": "api/values",
15 | "environmentVariables": {
16 | "ASPNETCORE_ENVIRONMENT": "Development"
17 | }
18 | },
19 | "AspectCore.Extensions.Autofac.WebSample": {
20 | "commandName": "Project",
21 | "launchBrowser": true,
22 | "launchUrl": "api/values",
23 | "environmentVariables": {
24 | "ASPNETCORE_ENVIRONMENT": "Development"
25 | },
26 | "applicationUrl": "http://localhost:16955/"
27 | }
28 | }
29 | }
30 |
--------------------------------------------------------------------------------
/extras/sample/AspectCore.Extensions.Autofac.WebSample/Services/IValuesService.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Threading.Tasks;
5 |
6 | namespace AspectCore.Extensions.Autofac.WebSample
7 | {
8 | public interface IValuesService
9 | {
10 | IEnumerable GetAll();
11 | }
12 |
13 | public class ValuesService : IValuesService
14 | {
15 | public IEnumerable GetAll()
16 | {
17 | return new string[] { "value", "value" };
18 | }
19 | }
20 | }
21 |
--------------------------------------------------------------------------------
/extras/sample/AspectCore.Extensions.Autofac.WebSample/appsettings.Development.json:
--------------------------------------------------------------------------------
1 | {
2 | "Logging": {
3 | "IncludeScopes": false,
4 | "LogLevel": {
5 | "Default": "Debug",
6 | "System": "Information",
7 | "Microsoft": "Information"
8 | }
9 | }
10 | }
11 |
--------------------------------------------------------------------------------
/extras/sample/AspectCore.Extensions.Autofac.WebSample/appsettings.json:
--------------------------------------------------------------------------------
1 | {
2 | "Logging": {
3 | "IncludeScopes": false,
4 | "LogLevel": {
5 | "Default": "Warning"
6 | }
7 | }
8 | }
--------------------------------------------------------------------------------
/extras/sample/AspectCore.Extensions.DependencyInjection.ConsoleSample/AspectCore.Extensions.DependencyInjection.ConsoleSample.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 | Exe
4 | netcoreapp2.0
5 |
6 |
7 |
8 |
9 |
--------------------------------------------------------------------------------
/extras/sample/AspectCore.Extensions.DependencyInjection.Sample/AspectCore.Extensions.DependencyInjection.Sample.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | netcoreapp2.0
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
--------------------------------------------------------------------------------
/extras/sample/AspectCore.Extensions.DependencyInjection.Sample/Controllers/ControllerBase.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Threading.Tasks;
5 | using Microsoft.AspNetCore.Mvc;
6 |
7 | namespace AspectCore.Extensions.DependencyInjection.Sample.Controllers
8 | {
9 | public abstract class ControllerBase : Controller
10 | {
11 | public virtual IActionResult ApiResult(Func func)
12 | {
13 | return func();
14 | }
15 |
16 | public virtual IEnumerable ApiResult(Func> func)
17 | {
18 | return func();
19 | }
20 | }
21 | }
--------------------------------------------------------------------------------
/extras/sample/AspectCore.Extensions.DependencyInjection.Sample/DynamicProxy/MethodExecuteLoggerInterceptor.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Diagnostics;
3 | using System.Threading.Tasks;
4 | using AspectCore.DynamicProxy;
5 | using AspectCore.Injector;
6 | using Microsoft.Extensions.Logging;
7 |
8 | namespace AspectCore.Extensions.DependencyInjection.Sample.DynamicProxy
9 | {
10 | public class MethodExecuteLoggerInterceptor : AbstractInterceptor
11 | {
12 | public async override Task Invoke(AspectContext context, AspectDelegate next)
13 | {
14 | Stopwatch stopwatch = Stopwatch.StartNew();
15 | await next(context);
16 | stopwatch.Stop();
17 | Console.WriteLine("Executed method {0}.{1}.{2} ({3}) in {4}ms",
18 | context.ServiceMethod.DeclaringType.Namespace,
19 | context.ServiceMethod.DeclaringType.Name,
20 | context.ServiceMethod.Name,
21 | context.ServiceMethod.DeclaringType.Assembly.GetName().Name,
22 | stopwatch.ElapsedMilliseconds
23 | );
24 | }
25 | }
26 | }
--------------------------------------------------------------------------------
/extras/sample/AspectCore.Extensions.DependencyInjection.Sample/Program.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.IO;
4 | using System.Linq;
5 | using System.Threading.Tasks;
6 | using Microsoft.AspNetCore;
7 | using Microsoft.AspNetCore.Hosting;
8 | using Microsoft.Extensions.Configuration;
9 | using Microsoft.Extensions.Logging;
10 |
11 | namespace AspectCore.Extensions.DependencyInjection.Sample
12 | {
13 | public class Program
14 | {
15 | public static void Main(string[] args)
16 | {
17 | BuildWebHost(args).Run();
18 | }
19 |
20 | public static IWebHost BuildWebHost(string[] args) =>
21 | WebHost.CreateDefaultBuilder(args)
22 | .UseStartup()
23 | .ConfigureLogging(b => b.ClearProviders())
24 | .Build();
25 | }
26 | }
--------------------------------------------------------------------------------
/extras/sample/AspectCore.Extensions.DependencyInjection.Sample/Properties/launchSettings.json:
--------------------------------------------------------------------------------
1 | {
2 | "iisSettings": {
3 | "windowsAuthentication": false,
4 | "anonymousAuthentication": true,
5 | "iisExpress": {
6 | "applicationUrl": "http://localhost:3980/",
7 | "sslPort": 0
8 | }
9 | },
10 | "profiles": {
11 | "IIS Express": {
12 | "commandName": "IISExpress",
13 | "launchBrowser": true,
14 | "launchUrl": "api/values",
15 | "environmentVariables": {
16 | "ASPNETCORE_ENVIRONMENT": "Development"
17 | }
18 | },
19 | "AspectCore.Extensions.DependencyInjection.Sample": {
20 | "commandName": "Project",
21 | "launchBrowser": true,
22 | "launchUrl": "api/values",
23 | "environmentVariables": {
24 | "ASPNETCORE_ENVIRONMENT": "Development"
25 | },
26 | "applicationUrl": "http://localhost:3981/"
27 | }
28 | }
29 | }
30 |
--------------------------------------------------------------------------------
/extras/sample/AspectCore.Extensions.DependencyInjection.Sample/Services/IValuesService.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Threading.Tasks;
5 |
6 | namespace AspectCore.Extensions.DependencyInjection.Sample.Services
7 | {
8 | public interface IValuesService
9 | {
10 | IEnumerable GetAll();
11 | }
12 |
13 | public class ValuesService : IValuesService
14 | {
15 | public IEnumerable GetAll()
16 | {
17 | return new string[] { "value", "value" };
18 | }
19 | }
20 | }
21 |
--------------------------------------------------------------------------------
/extras/sample/AspectCore.Extensions.DependencyInjection.Sample/appsettings.Development.json:
--------------------------------------------------------------------------------
1 | {
2 | "Logging": {
3 | "IncludeScopes": false,
4 | "LogLevel": {
5 | "Default": "Debug",
6 | "System": "Information",
7 | "Microsoft": "Information"
8 | }
9 | }
10 | }
11 |
--------------------------------------------------------------------------------
/extras/sample/AspectCore.Extensions.DependencyInjection.Sample/appsettings.json:
--------------------------------------------------------------------------------
1 | {
2 | "Logging": {
3 | "IncludeScopes": false,
4 | "LogLevel": {
5 | "Default": "Warning"
6 | }
7 | }
8 | }
--------------------------------------------------------------------------------
/extras/src/AspectCore.Extensions.AspNetCore/Extensions/AspectContextExtensions.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using Microsoft.AspNetCore.Http;
3 | using Microsoft.Extensions.DependencyInjection;
4 |
5 | namespace AspectCore.DynamicProxy
6 | {
7 | public static class AspectContextExtensions
8 | {
9 | public static HttpContext GetHttpContext(this AspectContext aspectContext)
10 | {
11 | if (aspectContext == null)
12 | {
13 | throw new ArgumentNullException(nameof(aspectContext));
14 | }
15 | var httpContextAccessor = aspectContext.ServiceProvider.GetService();
16 | return httpContextAccessor?.HttpContext;
17 | }
18 | }
19 | }
20 |
--------------------------------------------------------------------------------
/extras/src/AspectCore.Extensions.AspNetCore/Extensions/ConfigurationExtensions.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using AspectCore.Configuration;
3 |
4 | namespace AspectCore.Extensions.AspNetCore
5 | {
6 | public static class ConfigurationExtensions
7 | {
8 | public static IAspectConfiguration AddMethodExecuteLogging(this IAspectConfiguration configuration, params AspectPredicate[] predicates)
9 | {
10 | if (configuration == null)
11 | {
12 | throw new ArgumentNullException(nameof(configuration));
13 | }
14 | configuration.Interceptors.AddTyped(predicates);
15 | return configuration;
16 | }
17 | }
18 | }
19 |
--------------------------------------------------------------------------------
/extras/src/AspectCore.Extensions.AspNetCore/Filters/ModelStateAdapterAttribute.cs:
--------------------------------------------------------------------------------
1 | using Microsoft.AspNetCore.Mvc.Filters;
2 |
3 | namespace AspectCore.Extensions.AspNetCore.Filters
4 | {
5 | public class ModelStateAdapterAttribute : ActionFilterAttribute
6 | {
7 | public override void OnActionExecuting(ActionExecutingContext context)
8 | {
9 | context.HttpContext.Items["modelstate-aspectcore"] = context.ModelState;
10 | base.OnActionExecuting(context);
11 | }
12 | }
13 | }
--------------------------------------------------------------------------------
/extras/src/AspectCore.Extensions.AspNetCore/Http/ExecutionContextHelper.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Text;
4 | using System.Threading;
5 |
6 | namespace AspectCore.Extensions.AspNetCore.Http
7 | {
8 | public static class ExecutionContextHelper
9 | {
10 | public static ExecutionContext Current { get; set; }
11 | }
12 | }
13 |
--------------------------------------------------------------------------------
/extras/src/AspectCore.Extensions.Autofac/AspectCore.Extensions.Autofac.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 | Interceptor and dynamicProxy support for Autofac via AspectCore Framework.
8 | AspectCore.Extensions.Autofac
9 | net45;netstandard1.6
10 | AspectCore.Extensions.Autofac
11 | AspectCore.Extensions.Autofac
12 | DynamicProxy;Aop;Autofac;AspectCore
13 | Interceptor and dynamicProxy support for Autofac via AspectCore Framework.
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
--------------------------------------------------------------------------------
/extras/src/AspectCore.Extensions.Autofac/AutofacScopeResolverFactory.cs:
--------------------------------------------------------------------------------
1 | using AspectCore.DynamicProxy;
2 | using AspectCore.Injector;
3 | using Autofac;
4 |
5 | namespace AspectCore.Extensions.Autofac
6 | {
7 | [NonAspect]
8 | internal class AutofacScopeResolverFactory : IScopeResolverFactory
9 | {
10 | private readonly ILifetimeScope _lifetimeScope;
11 |
12 | public AutofacScopeResolverFactory(ILifetimeScope lifetimeScope)
13 | {
14 | this._lifetimeScope = lifetimeScope;
15 | }
16 |
17 | public IServiceResolver CreateScope()
18 | {
19 | return new AutofacServiceResolver(_lifetimeScope.BeginLifetimeScope());
20 | }
21 | }
22 | }
--------------------------------------------------------------------------------
/extras/src/AspectCore.Extensions.Autofac/AutofacServiceResolver.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using AspectCore.DynamicProxy;
3 | using AspectCore.Injector;
4 | using Autofac;
5 |
6 | namespace AspectCore.Extensions.Autofac
7 | {
8 | [NonAspect]
9 | internal class AutofacServiceResolver : IServiceResolver
10 | {
11 | private readonly IComponentContext _componentContext;
12 |
13 | public AutofacServiceResolver(IComponentContext componentContext)
14 | {
15 | _componentContext = componentContext;
16 | }
17 |
18 | public void Dispose()
19 | {
20 | var d = _componentContext as IDisposable;
21 | d?.Dispose();
22 | }
23 |
24 | public object GetService(Type serviceType)
25 | {
26 | return _componentContext.ResolveOptional(serviceType);
27 | }
28 |
29 | public object Resolve(Type serviceType)
30 | {
31 | return _componentContext.ResolveOptional(serviceType);
32 | }
33 | }
34 | }
--------------------------------------------------------------------------------
/extras/src/AspectCore.Extensions.Autofac/Properties/AssemblyInfo.cs:
--------------------------------------------------------------------------------
1 | using System.Reflection;
2 | using System.Runtime.CompilerServices;
3 | using System.Runtime.InteropServices;
4 |
5 | // General Information about an assembly is controlled through the following
6 | // set of attributes. Change these attribute values to modify the information
7 | // associated with an assembly.
8 | [assembly: AssemblyConfiguration("")]
9 | [assembly: AssemblyCompany("")]
10 | [assembly: AssemblyProduct("AspectCore.Container.Autofac")]
11 | [assembly: AssemblyTrademark("")]
12 |
13 | // Setting ComVisible to false makes the types in this assembly not visible
14 | // to COM components. If you need to access a type in this assembly from
15 | // COM, set the ComVisible attribute to true on that type.
16 | [assembly: ComVisible(false)]
17 |
18 | // The following GUID is for the ID of the typelib if this project is exposed to COM
19 | [assembly: Guid("05c1db04-90da-4d5d-a2a0-655dcc14e1f8")]
20 |
--------------------------------------------------------------------------------
/extras/src/AspectCore.Extensions.DependencyInjection/AspectCoreServiceProviderFactory.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using AspectCore.DynamicProxy;
3 | using AspectCore.Injector;
4 | using Microsoft.Extensions.DependencyInjection;
5 |
6 | namespace AspectCore.Extensions.DependencyInjection
7 | {
8 | [NonAspect]
9 | public class AspectCoreServiceProviderFactory : IServiceProviderFactory
10 | {
11 | public IServiceContainer CreateBuilder(IServiceCollection services)
12 | {
13 | return services.ToServiceContainer();
14 | }
15 |
16 | public IServiceProvider CreateServiceProvider(IServiceContainer containerBuilder)
17 | {
18 | return containerBuilder.Build();
19 | }
20 | }
21 | }
--------------------------------------------------------------------------------
/extras/src/AspectCore.Extensions.DependencyInjection/DynamicProxyServiceProviderFactory.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using Microsoft.Extensions.DependencyInjection;
3 |
4 | namespace AspectCore.Extensions.DependencyInjection
5 | {
6 | public class DynamicProxyServiceProviderFactory : IServiceProviderFactory
7 | {
8 | public IServiceCollection CreateBuilder(IServiceCollection services)
9 | {
10 | return services;
11 | }
12 |
13 | public IServiceProvider CreateServiceProvider(IServiceCollection containerBuilder)
14 | {
15 | return containerBuilder.BuildAspectCoreServiceProvider();
16 | }
17 | }
18 | }
19 |
--------------------------------------------------------------------------------
/extras/src/AspectCore.Extensions.DependencyInjection/MsdiScopeResolverFactory.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using AspectCore.Injector;
3 | using Microsoft.Extensions.DependencyInjection;
4 |
5 | namespace AspectCore.Extensions.DependencyInjection
6 | {
7 | internal class MsdiScopeResolverFactory : IScopeResolverFactory
8 | {
9 | private readonly IServiceProvider _serviceProvider;
10 |
11 | public MsdiScopeResolverFactory(IServiceProvider serviceProvider)
12 | {
13 | _serviceProvider = serviceProvider;
14 | }
15 |
16 | public IServiceResolver CreateScope()
17 | {
18 | return new MsdiServiceResolver(_serviceProvider.CreateScope().ServiceProvider);
19 | }
20 | }
21 | }
22 |
--------------------------------------------------------------------------------
/extras/src/AspectCore.Extensions.DependencyInjection/MsdiServiceResolver.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using AspectCore.Injector;
3 |
4 | namespace AspectCore.Extensions.DependencyInjection
5 | {
6 | internal class MsdiServiceResolver : IServiceResolver
7 | {
8 | private readonly IServiceProvider _serviceProvider;
9 | public MsdiServiceResolver(IServiceProvider serviceProvider)
10 | {
11 | _serviceProvider = serviceProvider;
12 | }
13 |
14 | public void Dispose()
15 | {
16 | var d = _serviceProvider as IDisposable;
17 | d?.Dispose();
18 | }
19 |
20 | public object GetService(Type serviceType)
21 | {
22 | return _serviceProvider.GetService(serviceType);
23 | }
24 |
25 | public object Resolve(Type serviceType)
26 | {
27 | return _serviceProvider.GetService(serviceType);
28 | }
29 | }
30 | }
31 |
--------------------------------------------------------------------------------
/extras/src/AspectCore.Extensions.DependencyInjection/Properties/AssemblyInfo.cs:
--------------------------------------------------------------------------------
1 | using System.Reflection;
2 | using System.Runtime.CompilerServices;
3 | using System.Runtime.InteropServices;
4 |
5 | // General Information about an assembly is controlled through the following
6 | // set of attributes. Change these attribute values to modify the information
7 | // associated with an assembly.
8 | [assembly: AssemblyConfiguration("")]
9 | [assembly: AssemblyCompany("")]
10 | [assembly: AssemblyProduct("AspectCore Framework")]
11 | [assembly: AssemblyTrademark("")]
12 |
13 | // Setting ComVisible to false makes the types in this assembly not visible
14 | // to COM components. If you need to access a type in this assembly from
15 | // COM, set the ComVisible attribute to true on that type.
16 | [assembly: ComVisible(false)]
17 |
18 | // The following GUID is for the ID of the typelib if this project is exposed to COM
19 | [assembly: Guid("00642272-6be8-430c-93d5-db63fec23184")]
20 |
--------------------------------------------------------------------------------
/extras/src/AspectCore.Extensions.DependencyInjection/ServiceScope.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using AspectCore.Injector;
3 | using Microsoft.Extensions.DependencyInjection;
4 |
5 | namespace AspectCore.Extensions.DependencyInjection
6 | {
7 | internal class ServiceScope : IServiceScope
8 | {
9 | private readonly IServiceResolver _serviceResolver;
10 | public IServiceProvider ServiceProvider => _serviceResolver;
11 |
12 | public ServiceScope(IServiceResolver serviceResolver)
13 | {
14 | _serviceResolver = serviceResolver;
15 | }
16 |
17 | public void Dispose()
18 | {
19 | _serviceResolver.Dispose();
20 | }
21 | }
22 | }
23 |
--------------------------------------------------------------------------------
/extras/src/AspectCore.Extensions.DependencyInjection/ServiceScopeFactory.cs:
--------------------------------------------------------------------------------
1 | using AspectCore.Injector;
2 | using Microsoft.Extensions.DependencyInjection;
3 |
4 | namespace AspectCore.Extensions.DependencyInjection
5 | {
6 | internal class ServiceScopeFactory : IServiceScopeFactory
7 | {
8 | private readonly IServiceResolver _serviceResolver;
9 |
10 | public ServiceScopeFactory(IServiceResolver serviceResolver)
11 | {
12 | _serviceResolver = serviceResolver;
13 | }
14 |
15 | public IServiceScope CreateScope()
16 | {
17 | return new ServiceScope(_serviceResolver.CreateScope());
18 | }
19 | }
20 | }
21 |
--------------------------------------------------------------------------------
/extras/src/AspectCore.Extensions.DependencyInjection/SupportRequiredService.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using AspectCore.Injector;
3 | using Microsoft.Extensions.DependencyInjection;
4 |
5 | namespace AspectCore.Extensions.DependencyInjection
6 | {
7 | internal class SupportRequiredService : ISupportRequiredService
8 | {
9 | private readonly IServiceResolver _serviceResolver;
10 |
11 | public SupportRequiredService(IServiceResolver serviceResolver)
12 | {
13 | _serviceResolver = serviceResolver;
14 | }
15 |
16 | public object GetRequiredService(Type serviceType)
17 | {
18 | if (serviceType == null)
19 | {
20 | throw new ArgumentNullException(nameof(serviceType));
21 | }
22 | return _serviceResolver.ResolveRequired(serviceType);
23 | }
24 | }
25 | }
--------------------------------------------------------------------------------
/extras/src/AspectCore.Extensions.Hosting/AspectCore.Extensions.Hosting.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | netstandard2.0
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
--------------------------------------------------------------------------------
/extras/src/AspectCore.Extensions.Windsor/CompatibleCollectionResolver.cs:
--------------------------------------------------------------------------------
1 | using Castle.Core;
2 | using Castle.MicroKernel;
3 | using Castle.MicroKernel.Context;
4 | using Castle.MicroKernel.Resolvers.SpecializedResolvers;
5 |
6 | namespace AspectCore.Extensions.Windsor
7 | {
8 | public class CompatibleCollectionResolver : CollectionResolver
9 | {
10 | public CompatibleCollectionResolver(IKernel kernel)
11 | : base(kernel, allowEmptyCollections: true)
12 | {
13 | }
14 |
15 | public override bool CanResolve(CreationContext context, ISubDependencyResolver contextHandlerResolver, ComponentModel model,
16 | DependencyModel dependency)
17 | {
18 | if (kernel.HasComponent(dependency.TargetItemType))
19 | {
20 | return false;
21 | }
22 |
23 | return base.CanResolve(context, contextHandlerResolver, model, dependency);
24 | }
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/extras/src/AspectCore.Extensions.Windsor/WindsorAspectBuilderFactory.cs:
--------------------------------------------------------------------------------
1 | using System.Linq;
2 | using AspectCore.DynamicProxy;
3 |
4 | namespace AspectCore.Extensions.Windsor
5 | {
6 | [NonAspect]
7 | internal class WindsorAspectBuilderFactory : IAspectBuilderFactory
8 | {
9 | private readonly IAspectBuilderFactory _aspectBuilderFactory;
10 | private readonly AspectDelegate _complete;
11 |
12 | public WindsorAspectBuilderFactory(IAspectBuilderFactory aspectBuilderFactory, AspectDelegate complete)
13 | {
14 | _aspectBuilderFactory = aspectBuilderFactory;
15 | _complete = complete;
16 | }
17 |
18 | public IAspectBuilder Create(AspectContext context)
19 | {
20 | var builder = _aspectBuilderFactory.Create(context);
21 | return new AspectBuilder(_complete, builder.Delegates.ToList());
22 | }
23 | }
24 | }
--------------------------------------------------------------------------------
/extras/test/AspectCore.Extensions.Autofac.Test/Fakes/Controller.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Threading.Tasks;
5 |
6 | namespace AspectCore.Extensions.Test.Fakes
7 | {
8 | public class Controller : IController
9 | {
10 | public IService Service { get; }
11 |
12 | public Controller(IService service)
13 | {
14 | Service = service;
15 | }
16 |
17 | public Model Execute()
18 | {
19 | return Service.Get(100);
20 | }
21 | }
22 | }
23 |
--------------------------------------------------------------------------------
/extras/test/AspectCore.Extensions.Autofac.Test/Fakes/IController.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Threading.Tasks;
5 |
6 | namespace AspectCore.Extensions.Test.Fakes
7 | {
8 | [CacheInterceptor]
9 | public interface IController
10 | {
11 | IService Service { get; }
12 | Model Execute();
13 | }
14 | }
15 |
--------------------------------------------------------------------------------
/extras/test/AspectCore.Extensions.Autofac.Test/Fakes/IService.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Threading.Tasks;
5 |
6 | namespace AspectCore.Extensions.Test.Fakes
7 | {
8 | public interface IService
9 | {
10 | [CacheInterceptor]
11 | Model Get(int id);
12 | }
13 | }
14 |
--------------------------------------------------------------------------------
/extras/test/AspectCore.Extensions.Autofac.Test/Fakes/Model.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Threading.Tasks;
5 |
6 | namespace AspectCore.Extensions.Test.Fakes
7 | {
8 | public class Model
9 | {
10 | public int Id { get; set; }
11 |
12 | public Guid Version { get; set; }
13 | }
14 | }
15 |
--------------------------------------------------------------------------------
/extras/test/AspectCore.Extensions.Autofac.Test/Fakes/Service.cs:
--------------------------------------------------------------------------------
1 | using System;
2 |
3 | namespace AspectCore.Extensions.Test.Fakes
4 | {
5 | public class Service : IService
6 | {
7 | public virtual Model Get(int id)
8 | {
9 | return new Model { Id = id, Version = Guid.NewGuid() };
10 | }
11 | }
12 | }
13 |
--------------------------------------------------------------------------------
/extras/test/AspectCore.Extensions.Autofac.Test/Properties/AssemblyInfo.cs:
--------------------------------------------------------------------------------
1 | using System.Reflection;
2 | using System.Runtime.CompilerServices;
3 | using System.Runtime.InteropServices;
4 |
5 | // General Information about an assembly is controlled through the following
6 | // set of attributes. Change these attribute values to modify the information
7 | // associated with an assembly.
8 | [assembly: AssemblyConfiguration("")]
9 | [assembly: AssemblyCompany("")]
10 | [assembly: AssemblyProduct("AspectCore.Container.Autofac.Test")]
11 | [assembly: AssemblyTrademark("")]
12 |
13 | // Setting ComVisible to false makes the types in this assembly not visible
14 | // to COM components. If you need to access a type in this assembly from
15 | // COM, set the ComVisible attribute to true on that type.
16 | [assembly: ComVisible(false)]
17 |
18 | // The following GUID is for the ID of the typelib if this project is exposed to COM
19 | [assembly: Guid("42599bc2-6584-4ebe-ac03-743d4958a7c3")]
20 |
--------------------------------------------------------------------------------
/extras/test/AspectCore.Extensions.Autofac.Test/SpecificationTests.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using Autofac;
3 | using Autofac.Extensions.DependencyInjection;
4 | using Microsoft.Extensions.DependencyInjection;
5 | using Microsoft.Extensions.DependencyInjection.Specification;
6 |
7 | namespace AspectCore.Extensions.Autofac.Test
8 | {
9 | public class SpecificationTests : DependencyInjectionSpecificationTests
10 | {
11 | protected override IServiceProvider CreateServiceProvider(IServiceCollection serviceCollection)
12 | {
13 | var builder = new ContainerBuilder();
14 | builder.Populate(serviceCollection);
15 | return new AutofacServiceProvider(builder.Build());
16 | }
17 | }
18 | }
19 |
--------------------------------------------------------------------------------
/extras/test/AspectCore.Extensions.DependencyInjection.Test/Properties/AssemblyInfo.cs:
--------------------------------------------------------------------------------
1 | using System.Reflection;
2 | using System.Runtime.CompilerServices;
3 | using System.Runtime.InteropServices;
4 |
5 | // General Information about an assembly is controlled through the following
6 | // set of attributes. Change these attribute values to modify the information
7 | // associated with an assembly.
8 | [assembly: AssemblyConfiguration("")]
9 | [assembly: AssemblyCompany("")]
10 | [assembly: AssemblyProduct("AspectCore.Container.DependencyInjection.Test")]
11 | [assembly: AssemblyTrademark("")]
12 |
13 | // Setting ComVisible to false makes the types in this assembly not visible
14 | // to COM components. If you need to access a type in this assembly from
15 | // COM, set the ComVisible attribute to true on that type.
16 | [assembly: ComVisible(false)]
17 |
18 | // The following GUID is for the ID of the typelib if this project is exposed to COM
19 | [assembly: Guid("a8b2b7ad-f5cd-4fb7-b0cf-a35a6c33aea7")]
20 |
--------------------------------------------------------------------------------
/extras/test/AspectCore.Extensions.DependencyInjection.Test/SpecificationTests.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using Microsoft.Extensions.DependencyInjection;
3 | using Microsoft.Extensions.DependencyInjection.Specification;
4 |
5 | namespace AspectCore.Extensions.DependencyInjection.Test
6 | {
7 | //public class SpecificationTests : DependencyInjectionSpecificationTests
8 | //{
9 | // protected override IServiceProvider CreateServiceProvider(IServiceCollection serviceCollection)
10 | // {
11 | // serviceCollection.AddAspectCore(option =>
12 | // {
13 | // option.InterceptorFactories.AddDelegate((ctx, next) => next(ctx));
14 | // option.InterceptorFactories.AddDelegate(next => ctx => next(ctx));
15 | // });
16 | // return serviceCollection.BuildAspectCoreServiceProvider();
17 | // }
18 | //}
19 | }
20 |
--------------------------------------------------------------------------------
/extras/test/AspectCore.Extensions.DependencyInjection.Test/UseMicrosoftDISpecificationTests.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using AspectCore.Configuration;
3 | using Microsoft.Extensions.DependencyInjection;
4 | using Microsoft.Extensions.DependencyInjection.Specification;
5 |
6 | namespace AspectCore.Extensions.DependencyInjection.Test
7 | {
8 | public class UseMicrosoftDISpecificationTests : DependencyInjectionSpecificationTests
9 | {
10 | protected override IServiceProvider CreateServiceProvider(IServiceCollection serviceCollection)
11 | {
12 | serviceCollection.AddDynamicProxy(config =>
13 | {
14 | config.Interceptors.AddDelegate((ctx, next) => next(ctx));
15 | });
16 |
17 | return serviceCollection.BuildAspectCoreServiceProvider();
18 | }
19 | }
20 | }
--------------------------------------------------------------------------------
/extras/test/AspectCore.Extensions.DependencyInjection.Test/Use_Built_In_ContainerSpecificationTests.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using AspectCore.Configuration;
3 | using AspectCore.Injector;
4 | using Microsoft.Extensions.DependencyInjection;
5 | using Microsoft.Extensions.DependencyInjection.Specification;
6 |
7 | namespace AspectCore.Extensions.DependencyInjection.Test
8 | {
9 | // public class Use_Built_In_ContainerSpecificationTests : DependencyInjectionSpecificationTests
10 | // {
11 | // protected override IServiceProvider CreateServiceProvider(IServiceCollection serviceCollection)
12 | // {
13 | // IServiceContainer container = serviceCollection.ToServiceContainer();
14 | //
15 | // container.Configuration.Interceptors.AddDelegate((ctx, next) => next(ctx));
16 | //
17 | // return container.Build();
18 | // }
19 | // }
20 | }
--------------------------------------------------------------------------------
/extras/test/AspectCore.Extensions.Hosting.Tests/AspectCore.Extensions.Hosting.Tests.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | netcoreapp2.0
5 |
6 | false
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
--------------------------------------------------------------------------------
/extras/test/AspectCore.Extensions.Hosting.Tests/FakeClasses.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Text;
4 |
5 | namespace Extensions.Hosting.Tests
6 | {
7 | public interface IService
8 | {
9 | string GetValue();
10 | }
11 |
12 | public class Service : IService
13 | {
14 | public string GetValue()
15 | {
16 | return "service";
17 | }
18 | }
19 | }
20 |
--------------------------------------------------------------------------------
/extras/test/AspectCore.Extensions.Windsor.Test/AspectCore.Extensions.Windsor.Test.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | netcoreapp2.0
5 |
6 | false
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
--------------------------------------------------------------------------------
/extras/test/AspectCore.Extensions.Windsor.Test/Fakes/CacheService.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Threading.Tasks;
3 |
4 | namespace AspectCore.Extensions.Windsor.Test.Fakes
5 | {
6 | public class CacheService : ICacheService
7 | {
8 | public Model Get(int id)
9 | {
10 | return new Model { Id = id, Version = Guid.NewGuid() };
11 | }
12 |
13 | public Task GetAsync(int id)
14 | {
15 | return Task.FromResult(Get(id));
16 | }
17 | }
18 | }
19 |
--------------------------------------------------------------------------------
/extras/test/AspectCore.Extensions.Windsor.Test/Fakes/Controller.cs:
--------------------------------------------------------------------------------
1 | namespace AspectCore.Extensions.Windsor.Test.Fakes
2 | {
3 | public class Controller : IController
4 | {
5 | public ICacheService Service { get; }
6 |
7 | public Controller(ICacheService service)
8 | {
9 | Service = service;
10 | }
11 |
12 | public Model Execute()
13 | {
14 | return Service.Get(100);
15 | }
16 | }
17 | }
18 |
--------------------------------------------------------------------------------
/extras/test/AspectCore.Extensions.Windsor.Test/Fakes/ICacheService.cs:
--------------------------------------------------------------------------------
1 | using System.Threading.Tasks;
2 |
3 | namespace AspectCore.Extensions.Windsor.Test.Fakes
4 | {
5 | public interface ICacheService
6 | {
7 | [CacheInterceptor]
8 | Model Get(int id);
9 |
10 | [CacheInterceptor]
11 | Task GetAsync(int id);
12 | }
13 | }
14 |
--------------------------------------------------------------------------------
/extras/test/AspectCore.Extensions.Windsor.Test/Fakes/IController.cs:
--------------------------------------------------------------------------------
1 | namespace AspectCore.Extensions.Windsor.Test.Fakes
2 | {
3 | [CacheInterceptor]
4 | public interface IController
5 | {
6 | ICacheService Service { get; }
7 | Model Execute();
8 | }
9 | }
10 |
--------------------------------------------------------------------------------
/extras/test/AspectCore.Extensions.Windsor.Test/Fakes/Model.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 |
4 | namespace AspectCore.Extensions.Windsor.Test.Fakes
5 | {
6 | public class Model
7 | {
8 | public int Id { get; set; }
9 |
10 | public Guid Version { get; set; }
11 | }
12 | }
13 |
--------------------------------------------------------------------------------
/reflection/README.md:
--------------------------------------------------------------------------------
1 | 在从零实现AOP的过程中,难免会需要大量反射相关的操作,虽然在.net 4.5+/.net core中反射的性能有了大幅的优化,但为了追求极致性能,自己实现了部分反射的替代方案,包括构造器调用、方法调用、字段读写,属性读写和特性读取。在重构时,把反射扩展操作封装到单独的项目中,以此方便自己和大家使用。[获取AspectCore.Extension.Reflection](https://github.com/dotnetcore/AspectCore-Framework/blob/master/docs/reflection-extensions.md)
--------------------------------------------------------------------------------
/reflection/performance/AspectCore.Extensions.Reflection.Benchmark/AspectCore.Extensions.Reflection.Benchmark.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | Exe
5 | netcoreapp1.1
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
--------------------------------------------------------------------------------
/reflection/performance/AspectCore.Extensions.Reflection.Benchmark/Fakes/ConstructorFakes.cs:
--------------------------------------------------------------------------------
1 | using System.Runtime.CompilerServices;
2 |
3 | namespace AspectCore.Extensions.Reflection.Benchmark.Fakes
4 | {
5 | public class ConstructorFakes
6 | {
7 | public string Name { get; set; }
8 |
9 | [MethodImpl(MethodImplOptions.NoInlining)]
10 | public ConstructorFakes()
11 | {
12 | //Name = "Nonparametric constructor";
13 | }
14 |
15 | [MethodImpl(MethodImplOptions.NoInlining)]
16 | public ConstructorFakes(string name)
17 | {
18 | Name = "Parametric constructor. param : " + name;
19 | }
20 |
21 | [MethodImpl(MethodImplOptions.NoInlining)]
22 | public ConstructorFakes(ref string name, ref ConstructorFakes fakes)
23 | {
24 | name = Name = "Parametric constructor with ref param.";
25 | fakes = new ConstructorFakes();
26 | }
27 | }
28 | }
29 |
--------------------------------------------------------------------------------
/reflection/performance/AspectCore.Extensions.Reflection.Benchmark/Fakes/FieldFakes.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Text;
5 | using System.Threading.Tasks;
6 |
7 | namespace AspectCore.Extensions.Reflection.Benchmark.Fakes
8 | {
9 | public class FieldFakes
10 | {
11 | public static string StaticFiled;
12 |
13 | public string InstanceField;
14 | }
15 | }
16 |
--------------------------------------------------------------------------------
/reflection/performance/AspectCore.Extensions.Reflection.Benchmark/Fakes/MethodFakes.cs:
--------------------------------------------------------------------------------
1 | using System.Runtime.CompilerServices;
2 |
3 | namespace AspectCore.Extensions.Reflection.Benchmark.Fakes
4 | {
5 | public class MethodFakes
6 | {
7 | [MethodImpl(MethodImplOptions.NoInlining)]
8 | public object Call() => null;
9 | [MethodImpl(MethodImplOptions.NoInlining)]
10 | public static object StaticCall() => null;
11 | [MethodImpl(MethodImplOptions.NoInlining)]
12 | public virtual object CallVirt() => null;
13 | }
14 | }
--------------------------------------------------------------------------------
/reflection/performance/AspectCore.Extensions.Reflection.Benchmark/Fakes/PropertyFakes.cs:
--------------------------------------------------------------------------------
1 | using System.Runtime.CompilerServices;
2 |
3 | namespace AspectCore.Extensions.Reflection.Benchmark.Fakes
4 | {
5 | public class PropertyFakes
6 | {
7 | public static string StaticProperty { [MethodImpl(MethodImplOptions.NoInlining)]get; [MethodImpl(MethodImplOptions.NoInlining)]set; }
8 |
9 | public string InstanceProperty { [MethodImpl(MethodImplOptions.NoInlining)]get; [MethodImpl(MethodImplOptions.NoInlining)]set; }
10 | }
11 | }
--------------------------------------------------------------------------------
/reflection/performance/AspectCore.Extensions.Reflection.Benchmark/Program.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using AspectCore.Extensions.Reflection.Benchmark.Benchmarks;
3 | using BenchmarkDotNet.Running;
4 |
5 | namespace AspectCore.Extensions.Reflection.Benchmark
6 | {
7 | static class Program
8 | {
9 | static void Main(string[] args)
10 | {
11 | //BenchmarkRunner.Run();
12 | //BenchmarkRunner.Run();
13 | //BenchmarkRunner.Run();
14 | BenchmarkRunner.Run();
15 | //BenchmarkRunner.Run();
16 | }
17 | }
18 | }
--------------------------------------------------------------------------------
/reflection/src/AspectCore.Extensions.Reflection/CallOptions.cs:
--------------------------------------------------------------------------------
1 | namespace AspectCore.Extensions.Reflection
2 | {
3 | public enum CallOptions
4 | {
5 | Call,
6 | Callvirt
7 | }
8 | }
9 |
--------------------------------------------------------------------------------
/reflection/src/AspectCore.Extensions.Reflection/ConstructorReflector.OpenGeneric.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Reflection;
4 | using System.Text;
5 |
6 | namespace AspectCore.Extensions.Reflection
7 | {
8 | public partial class ConstructorReflector
9 | {
10 | private class OpenGenericConstructorReflector : ConstructorReflector
11 | {
12 | public OpenGenericConstructorReflector(ConstructorInfo constructorInfo) : base(constructorInfo)
13 | {
14 | }
15 |
16 | protected override Func