Skip to content

Commit ba459a9

Browse files
authored
Merge pull request #12 from MrDave1999/shared-entities-sample
Add Shared.Entities project as a sample and use it in both host and plugins
2 parents 44da624 + 0910b87 commit ba459a9

14 files changed

Lines changed: 156 additions & 5 deletions

CPlugin.Net.sln

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,16 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Example.ConsoleApp", "sampl
1313
EndProject
1414
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Example.WebApi", "samples\HostApplications\WebApi\Example.WebApi.csproj", "{C221B4F0-857F-4380-B5AD-E4B2BBA65622}"
1515
EndProject
16+
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Example.SharedEntities", "samples\SharedEntities\Example.SharedEntities.csproj", "{F66A1430-3F32-4E25-8966-54D502D216DE}"
17+
EndProject
1618
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Example.JsonPlugin", "samples\Plugins\JsonPlugin\Example.JsonPlugin.csproj", "{C5B8EF73-7DB5-441F-AE38-0988751A896B}"
1719
EndProject
1820
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Example.OldJsonPlugin", "samples\Plugins\OldJsonPlugin\Example.OldJsonPlugin.csproj", "{1ADE3B86-00EF-4976-8B67-09B360B149FA}"
1921
EndProject
2022
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Example.AppointmentPlugin", "samples\Plugins\AppointmentPlugin\Example.AppointmentPlugin.csproj", "{2832E5C3-660E-49B9-8E62-03B11A8CC6D7}"
2123
EndProject
24+
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Example.PersonPlugin", "samples\Plugins\PersonPlugin\Example.PersonPlugin.csproj", "{18534944-583B-4924-AC5B-E0655FD92AAC}"
25+
EndProject
2226
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{DA150C23-F1A9-42CF-899C-6C4E6B940E72}"
2327
ProjectSection(SolutionItems) = preProject
2428
Directory.Build.props = Directory.Build.props
@@ -36,6 +40,10 @@ Global
3640
{D9737294-F5EA-4EA0-8BF2-2BF5C3954DD9}.Debug|Any CPU.Build.0 = Debug|Any CPU
3741
{D9737294-F5EA-4EA0-8BF2-2BF5C3954DD9}.Release|Any CPU.ActiveCfg = Release|Any CPU
3842
{D9737294-F5EA-4EA0-8BF2-2BF5C3954DD9}.Release|Any CPU.Build.0 = Release|Any CPU
43+
{116B353F-FC68-4412-8A2D-34DA0BE88060}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
44+
{116B353F-FC68-4412-8A2D-34DA0BE88060}.Debug|Any CPU.Build.0 = Debug|Any CPU
45+
{116B353F-FC68-4412-8A2D-34DA0BE88060}.Release|Any CPU.ActiveCfg = Release|Any CPU
46+
{116B353F-FC68-4412-8A2D-34DA0BE88060}.Release|Any CPU.Build.0 = Release|Any CPU
3947
{BBDE7F3C-2A41-40B6-B609-839D09676D0E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
4048
{BBDE7F3C-2A41-40B6-B609-839D09676D0E}.Debug|Any CPU.Build.0 = Debug|Any CPU
4149
{BBDE7F3C-2A41-40B6-B609-839D09676D0E}.Release|Any CPU.ActiveCfg = Release|Any CPU
@@ -60,10 +68,14 @@ Global
6068
{2832E5C3-660E-49B9-8E62-03B11A8CC6D7}.Debug|Any CPU.Build.0 = Debug|Any CPU
6169
{2832E5C3-660E-49B9-8E62-03B11A8CC6D7}.Release|Any CPU.ActiveCfg = Release|Any CPU
6270
{2832E5C3-660E-49B9-8E62-03B11A8CC6D7}.Release|Any CPU.Build.0 = Release|Any CPU
63-
{116B353F-FC68-4412-8A2D-34DA0BE88060}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
64-
{116B353F-FC68-4412-8A2D-34DA0BE88060}.Debug|Any CPU.Build.0 = Debug|Any CPU
65-
{116B353F-FC68-4412-8A2D-34DA0BE88060}.Release|Any CPU.ActiveCfg = Release|Any CPU
66-
{116B353F-FC68-4412-8A2D-34DA0BE88060}.Release|Any CPU.Build.0 = Release|Any CPU
71+
{18534944-583B-4924-AC5B-E0655FD92AAC}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
72+
{18534944-583B-4924-AC5B-E0655FD92AAC}.Debug|Any CPU.Build.0 = Debug|Any CPU
73+
{18534944-583B-4924-AC5B-E0655FD92AAC}.Release|Any CPU.ActiveCfg = Release|Any CPU
74+
{18534944-583B-4924-AC5B-E0655FD92AAC}.Release|Any CPU.Build.0 = Release|Any CPU
75+
{F66A1430-3F32-4E25-8966-54D502D216DE}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
76+
{F66A1430-3F32-4E25-8966-54D502D216DE}.Debug|Any CPU.Build.0 = Debug|Any CPU
77+
{F66A1430-3F32-4E25-8966-54D502D216DE}.Release|Any CPU.ActiveCfg = Release|Any CPU
78+
{F66A1430-3F32-4E25-8966-54D502D216DE}.Release|Any CPU.Build.0 = Release|Any CPU
6779
EndGlobalSection
6880
GlobalSection(SolutionProperties) = preSolution
6981
HideSolutionNode = FALSE
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
namespace Example.WebApi.Controllers;
2+
3+
[ApiController]
4+
[Route("[controller]")]
5+
public class PeopleController
6+
{
7+
private readonly List<Person> _persons;
8+
public PeopleController(List<Person> persons) => _persons = persons;
9+
10+
[HttpGet]
11+
public Result<List<Person>> GetAll() => Result.Success(_persons);
12+
}

samples/HostApplications/WebApi/Example.WebApi.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
<ItemGroup>
1414
<ProjectReference Include="..\..\..\src\Core\CPlugin.Net.csproj" />
1515
<ProjectReference Include="..\..\Contracts\Example.Contracts.csproj" />
16+
<ProjectReference Include="..\..\SharedEntities\Example.SharedEntities.csproj" />
1617
</ItemGroup>
1718

1819
</Project>

samples/HostApplications/WebApi/GlobalUsings.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,4 @@
44
global using Microsoft.AspNetCore.Mvc;
55
global using Microsoft.AspNetCore.Mvc.ApplicationParts;
66
global using SimpleResults;
7+
global using Example.SharedEntities;

samples/HostApplications/WebApi/appsettings.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
},
88
"AllowedHosts": "*",
99
"Plugins": [
10-
"Example.AppointmentPlugin.dll"
10+
"Example.AppointmentPlugin.dll",
11+
"Example.PersonPlugin.dll"
1112
]
1213
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<Project Sdk="Microsoft.NET.Sdk.Web">
2+
3+
<PropertyGroup>
4+
<OutDir>$(WebApiProjectDir)</OutDir>
5+
<OutputType>Library</OutputType>
6+
<NoDefaultLaunchSettingsFile>true</NoDefaultLaunchSettingsFile>
7+
<ManagePackageVersionsCentrally>false</ManagePackageVersionsCentrally>
8+
</PropertyGroup>
9+
<ItemGroup>
10+
<ProjectReference Include="..\..\SharedEntities\Example.SharedEntities.csproj" Private="false" />
11+
</ItemGroup>
12+
13+
<ItemGroup>
14+
<PackageReference Include="SimpleResults" Version="0.3.0-alpha" />
15+
</ItemGroup>
16+
17+
</Project>
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
global using Microsoft.AspNetCore.Mvc;
2+
global using SimpleResults;
3+
global using Example.SharedEntities;
4+
global using Example.Contracts;
5+
global using CPlugin.Net;
6+
global using Example.PersonPlugin;
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
namespace Example.PersonPlugin;
2+
3+
[ApiController]
4+
[Route("[controller]")]
5+
public class PersonController : ControllerBase
6+
{
7+
[HttpGet]
8+
public Result<IEnumerable<Person>> GetAll(IPersonService service)
9+
=> service.GetAll();
10+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
namespace Example.PersonPlugin;
2+
3+
public interface IPersonService
4+
{
5+
Result<IEnumerable<Person>> GetAll();
6+
}
7+
8+
public class PersonService : IPersonService
9+
{
10+
private readonly List<Person> _persons;
11+
public PersonService(List<Person> persons) => _persons = persons;
12+
13+
public Result<IEnumerable<Person>> GetAll()
14+
{
15+
if (_persons.Count == 0)
16+
return Result.Success<IEnumerable<Person>>(_persons, "No results");
17+
18+
return Result.Success<IEnumerable<Person>>(_persons);
19+
}
20+
}
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
[assembly: Plugin(typeof(Startup))]
2+
3+
namespace Example.PersonPlugin;
4+
5+
public class Startup : IWebStartup
6+
{
7+
public string Name => "person";
8+
public string Description => "Expose endpoints.";
9+
10+
public void ConfigureServices(IServiceCollection services)
11+
{
12+
var persons = new List<Person>
13+
{
14+
new()
15+
{
16+
Id = 1,
17+
Name = "Alice",
18+
Document = "0923611701",
19+
DocumentType = DocumentTypes.IdentityCard
20+
},
21+
new()
22+
{
23+
Id = 2,
24+
Name = "Bob",
25+
Document = "0923611755",
26+
DocumentType = DocumentTypes.Passport
27+
},
28+
new()
29+
{
30+
Id = 3,
31+
Name = "Steven",
32+
Document = "0923611777",
33+
DocumentType = DocumentTypes.IdentityCard
34+
}
35+
};
36+
37+
services.AddSingleton(persons);
38+
services.AddTransient<IPersonService, PersonService>();
39+
}
40+
}

0 commit comments

Comments
 (0)