Skip to content

Commit 31171c9

Browse files
committed
Add project files.
1 parent 96830b5 commit 31171c9

31 files changed

+1443
-0
lines changed

.dockerignore

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
**/.classpath
2+
**/.dockerignore
3+
**/.env
4+
**/.git
5+
**/.gitignore
6+
**/.project
7+
**/.settings
8+
**/.toolstarget
9+
**/.vs
10+
**/.vscode
11+
**/*.*proj.user
12+
**/*.dbmdl
13+
**/*.jfm
14+
**/azds.yaml
15+
**/bin
16+
**/charts
17+
**/docker-compose*
18+
**/Dockerfile*
19+
**/node_modules
20+
**/npm-debug.log
21+
**/obj
22+
**/secrets.dev.yaml
23+
**/values.dev.yaml
24+
LICENSE
25+
README.md
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
using Microsoft.AspNetCore.Routing;
2+
using Microsoft.Extensions.DependencyInjection;
3+
4+
namespace MinimalApi.Extensions
5+
{
6+
public static class IEndpointRouteBuilderExtensions
7+
{
8+
public static void MapEndpoints(this IEndpointRouteBuilder builder)
9+
{
10+
var endpoints = builder.ServiceProvider.GetServices<IEndpoint>();
11+
12+
foreach (var endpoint in endpoints)
13+
{
14+
endpoint.AddRoute(builder);
15+
}
16+
}
17+
}
18+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
using Microsoft.Extensions.DependencyInjection;
2+
3+
namespace MinimalApi.Extensions
4+
{
5+
public static class IServiceCollectionExtensions
6+
{
7+
public static IServiceCollection AddEndpoints(this IServiceCollection services)
8+
{
9+
var endpoints = AppDomain.CurrentDomain.GetAssemblies()
10+
.SelectMany(s => s.GetTypes())
11+
.Where(t => t.GetInterfaces().Contains(typeof(IEndpoint)))
12+
.Where(t => !t.IsInterface);
13+
14+
foreach (var endpoint in endpoints)
15+
{
16+
services.AddSingleton(typeof(IEndpoint), endpoint);
17+
}
18+
19+
return services;
20+
}
21+
}
22+
}

MinimalApi/IEndpoint.cs

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
using Microsoft.AspNetCore.Routing;
2+
3+
namespace MinimalApi
4+
{
5+
6+
public interface IEndpoint
7+
{
8+
void AddRoute(IEndpointRouteBuilder app);
9+
}
10+
11+
public interface IEndpoint<TResult> : IEndpoint
12+
{
13+
Task<TResult> Handle();
14+
}
15+
16+
public interface IEndpoint<TResult, TRequest> : IEndpoint
17+
{
18+
Task<TResult> Handle(TRequest request);
19+
}
20+
21+
public interface IEndpoint<TResult, TRequest1, TRequest2> : IEndpoint
22+
{
23+
Task<TResult> Handle(TRequest1 request1, TRequest2 request2);
24+
}
25+
}

MinimalApi/MinimalApi.csproj

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<TargetFramework>net6.0</TargetFramework>
5+
<ImplicitUsings>enable</ImplicitUsings>
6+
<Nullable>enable</Nullable>
7+
</PropertyGroup>
8+
9+
<ItemGroup>
10+
<FrameworkReference Include="Microsoft.AspNetCore.App" />
11+
</ItemGroup>
12+
13+
</Project>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
start cmd /c StartApi.bat
2+
nswag run StructuredMinimalApiClient.nswag /runtime:Net60
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
cd..
2+
dotnet run --project StructuredMinimalApi/StructuredMinimalApi.csproj
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<TargetFramework>net6.0</TargetFramework>
5+
<ImplicitUsings>enable</ImplicitUsings>
6+
<Nullable>enable</Nullable>
7+
</PropertyGroup>
8+
9+
<ItemGroup>
10+
<PackageReference Include="Newtonsoft.Json" Version="13.0.1" />
11+
</ItemGroup>
12+
13+
</Project>

0 commit comments

Comments
 (0)