Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor: Refactor MinimalAPI #243

Merged
merged 15 commits into from
Sep 16, 2022
Merged
Show file tree
Hide file tree
Changes from 14 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions Masa.Framework.sln
Original file line number Diff line number Diff line change
Expand Up @@ -549,6 +549,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Masa.Contrib.Authentication
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Masa.Contrib.Authentication.OpenIdConnect.EFCore.Test", "src\Contrib\Authentication\Tests\Masa.Contrib.Authentication.OpenIdConnect.EFCore.Test\Masa.Contrib.Authentication.OpenIdConnect.EFCore.Test.csproj", "{F242EF1B-6951-4EE5-AF9C-CDC69D9A0260}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Masa.Utils.Extensions.DotNet.Tests", "src\Utils\Extensions\Tests\Masa.Utils.Extensions.DotNet.Tests\Masa.Utils.Extensions.DotNet.Tests.csproj", "{9E9122FD-8E27-4524-862F-FFEFA97E404A}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -1957,6 +1959,14 @@ Global
{F242EF1B-6951-4EE5-AF9C-CDC69D9A0260}.Release|Any CPU.Build.0 = Release|Any CPU
{F242EF1B-6951-4EE5-AF9C-CDC69D9A0260}.Release|x64.ActiveCfg = Release|Any CPU
{F242EF1B-6951-4EE5-AF9C-CDC69D9A0260}.Release|x64.Build.0 = Release|Any CPU
{9E9122FD-8E27-4524-862F-FFEFA97E404A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{9E9122FD-8E27-4524-862F-FFEFA97E404A}.Debug|Any CPU.Build.0 = Debug|Any CPU
{9E9122FD-8E27-4524-862F-FFEFA97E404A}.Debug|x64.ActiveCfg = Debug|Any CPU
{9E9122FD-8E27-4524-862F-FFEFA97E404A}.Debug|x64.Build.0 = Debug|Any CPU
{9E9122FD-8E27-4524-862F-FFEFA97E404A}.Release|Any CPU.ActiveCfg = Release|Any CPU
{9E9122FD-8E27-4524-862F-FFEFA97E404A}.Release|Any CPU.Build.0 = Release|Any CPU
{9E9122FD-8E27-4524-862F-FFEFA97E404A}.Release|x64.ActiveCfg = Release|Any CPU
{9E9122FD-8E27-4524-862F-FFEFA97E404A}.Release|x64.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down Expand Up @@ -2227,6 +2237,7 @@ Global
{583ECD6A-5960-4A60-833A-DB6DD93BE9C3} = {94D15C26-7204-4299-BC23-B89F5A0B0BF9}
{60A02980-398C-40CD-9FAA-ACAD7A9A866C} = {94D15C26-7204-4299-BC23-B89F5A0B0BF9}
{F242EF1B-6951-4EE5-AF9C-CDC69D9A0260} = {94D15C26-7204-4299-BC23-B89F5A0B0BF9}
{9E9122FD-8E27-4524-862F-FFEFA97E404A} = {C2FAC276-9D6E-498A-BBA2-F3F14ADF4D0D}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {40383055-CC50-4600-AD9A-53C14F620D03}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
// Copyright (c) MASA Stack All rights reserved.
// Copyright (c) MASA Stack All rights reserved.
// Licensed under the MIT License. See LICENSE.txt in the project root for license information.

namespace Microsoft.AspNetCore.Mvc;

[AttributeUsage(AttributeTargets.Method)]
public class ExcludeMappingAttribute: Attribute
public class IgnoreRouteAttribute: Attribute
{

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
// Copyright (c) MASA Stack All rights reserved.
// Licensed under the MIT License. See LICENSE.txt in the project root for license information.

namespace Microsoft.AspNetCore.Mvc;

[AttributeUsage(AttributeTargets.Method)]
public class RoutePatternAttribute : Attribute
{
public string Pattern { get; set; }

/// <summary>
/// The request method, the default is null (the request method is automatically identified according to the method name prefix)
/// </summary>
public string? HttpMethod { get; set; }

public bool StartWithBaseUri { get; set; }

public RoutePatternAttribute(string pattern, bool startWithBaseUri = false)
{
Pattern = pattern;
StartWithBaseUri = startWithBaseUri;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
// Copyright (c) MASA Stack All rights reserved.
// Licensed under the MIT License. See LICENSE.txt in the project root for license information.

namespace Masa.Contrib.Service.MinimalAPIs;

public static class ServiceBaseHelper
{
public static Delegate CreateDelegate(MethodInfo methodInfo, object targetInstance)
{
var type = Expression.GetDelegateType(methodInfo.GetParameters().Select(parameterInfo => parameterInfo.ParameterType)
.Concat(new List<Type>
{ methodInfo.ReturnType }).ToArray());
return Delegate.CreateDelegate(type, targetInstance, methodInfo);
}

public static string CombineUris(params string[] uris) => string.Join("/", uris.Select(u => u.Trim('/')));

public static string TrimEndMethodName(string methodName)
=> methodName.TrimEnd("Async", StringComparison.OrdinalIgnoreCase);

public static string ParseMethodPrefix(string[] prefixes, string methodName)
{
var newMethodName = methodName;
var prefix = prefixes.FirstOrDefault(prefix => newMethodName.StartsWith(prefix, StringComparison.OrdinalIgnoreCase));

if (prefix is not null)
return prefix;

return string.Empty;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
<ItemGroup>
<ProjectReference Include="..\..\..\BuildingBlocks\Data\Masa.BuildingBlocks.Data\Masa.BuildingBlocks.Data.csproj" />
<ProjectReference Include="..\..\..\BuildingBlocks\Service\Masa.BuildingBlocks.Service.MinimalAPIs\Masa.BuildingBlocks.Service.MinimalAPIs.csproj" />
<ProjectReference Include="..\..\..\Utils\Caching\Masa.Utils.Caching.Core\Masa.Utils.Caching.Core.csproj" />
<ProjectReference Include="..\..\..\Utils\Extensions\Masa.Utils.Extensions.DependencyInjection\Masa.Utils.Extensions.DependencyInjection.csproj" />
<ProjectReference Include="..\..\..\Utils\Extensions\Masa.Utils.Extensions.DotNet\Masa.Utils.Extensions.DotNet.csproj" />
</ItemGroup>
Expand Down

This file was deleted.

12 changes: 3 additions & 9 deletions src/Contrib/Service/Masa.Contrib.Service.MinimalAPIs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ Original usage:
```C#
var builder = WebApplication.CreateBuilder(args);
var app = builder.Build();
app.MapGet("/api/v1/helloworld", ()=>"Hello World");
app.MapGet("/api/v1/Demo/HelloWorld", () => "Hello World");
app.Run();
```

Expand All @@ -21,20 +21,14 @@ Install-Package Masa.Contrib.Service.MinimalAPIs

```c#
var builder = WebApplication.CreateBuilder(args);
var app = builder.Services
.AddServices(builder);
var app = builder.Services.AddServices(builder);
```

2. Custom Service and inherit ServiceBase

```c#
public class IntegrationEventService : ServiceBase
public class DemoService : ServiceBase
{
public IntegrationEventService(IServiceCollection services) : base(services)
{
App.MapGet("/api/v1/payment/HelloWorld", HelloWorld);
}

public string HelloWorld()
{
return "Hello World";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
```C#
var builder = WebApplication.CreateBuilder(args);
var app = builder.Build();
app.MapGet("/api/v1/helloworld", ()=>"Hello World");
app.MapGet("/api/v1/Demo/HelloWorld", () => "Hello World");
app.Run();
```

Expand All @@ -21,20 +21,14 @@ Install-Package Masa.Contrib.Service.MinimalAPIs

```c#
var builder = WebApplication.CreateBuilder(args);
var app = builder.Services
.AddServices(builder);
var app = builder.Services.AddServices(builder);
```

2. 自定义Service并继承ServiceBase,如:

```c#
public class IntegrationEventService : ServiceBase
public class DemoService : ServiceBase
{
public IntegrationEventService(IServiceCollection services) : base(services)
{
App.MapGet("/api/v1/payment/HelloWorld", HelloWorld);
}

public string HelloWorld()
{
return "Hello World";
Expand Down
Loading