Skip to content

WIP: Add Marten Client #60

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

Closed
wants to merge 17 commits into from
Closed
Show file tree
Hide file tree
Changes from all 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
37 changes: 37 additions & 0 deletions CommunityToolkit.Aspire.sln
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,17 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "CommunityToolkit.Aspire.Hos
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "CommunityToolkit.Aspire.Hosting.Meilisearch.ApiService", "examples\meilisearch\CommunityToolkit.Aspire.Hosting.Meilisearch.ApiService\CommunityToolkit.Aspire.Hosting.Meilisearch.ApiService.csproj", "{F6A9CC5C-91A2-4AAB-AEC9-8007A62A081E}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "CommunityToolkit.Aspire.Marten", "src\CommunityToolkit.Aspire.Marten\CommunityToolkit.Aspire.Marten.csproj", "{DFF1D3F3-31D3-44EA-ADB9-4BD7F7AF626D}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "CommunityToolkit.Aspire.Marten.Tests", "tests\CommunityToolkit.Aspire.Marten.Tests\CommunityToolkit.Aspire.Marten.Tests.csproj", "{8FC3E08E-8CEF-4D9A-9013-0B6AFE1BB05B}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "marten", "marten", "{89330EB0-DD97-43F1-93AE-8CAAD820F3D5}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "CommunityToolkit.Aspire.Marten.AppHost", "examples\marten\CommunityToolkit.Aspire.Marten.AppHost\CommunityToolkit.Aspire.Marten.AppHost.csproj", "{49669F3F-A5E4-4ABD-8CAE-C14E9D5C70B3}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "CommunityToolkit.Aspire.Marten.ApiService", "examples\marten\CommunityToolkit.Aspire.Marten.ApiService\CommunityToolkit.Aspire.Marten.ApiService.csproj", "{E022414D-36D8-436A-A66A-BEE337FEA712}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CommunityToolkit.Aspire.Marten.ServiceDefaults", "examples\marten\CommunityToolkit.Aspire.Marten.ServiceDefaults\CommunityToolkit.Aspire.Marten.ServiceDefaults.csproj", "{67CEEED4-72DA-4B09-93CE-D4313E3F410D}"
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "deno", "deno", "{B63EBC68-9A38-41C0-826E-95CD14B067A4}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "CommunityToolkit.Aspire.Hosting.Deno.Tests", "tests\CommunityToolkit.Aspire.Hosting.Deno.Tests\CommunityToolkit.Aspire.Hosting.Deno.Tests.csproj", "{A92E70F9-8028-4E0C-B167-884E1E56854F}"
Expand Down Expand Up @@ -233,6 +244,26 @@ Global
{F6A9CC5C-91A2-4AAB-AEC9-8007A62A081E}.Debug|Any CPU.Build.0 = Debug|Any CPU
{F6A9CC5C-91A2-4AAB-AEC9-8007A62A081E}.Release|Any CPU.ActiveCfg = Release|Any CPU
{F6A9CC5C-91A2-4AAB-AEC9-8007A62A081E}.Release|Any CPU.Build.0 = Release|Any CPU
{DFF1D3F3-31D3-44EA-ADB9-4BD7F7AF626D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{DFF1D3F3-31D3-44EA-ADB9-4BD7F7AF626D}.Debug|Any CPU.Build.0 = Debug|Any CPU
{DFF1D3F3-31D3-44EA-ADB9-4BD7F7AF626D}.Release|Any CPU.ActiveCfg = Release|Any CPU
{DFF1D3F3-31D3-44EA-ADB9-4BD7F7AF626D}.Release|Any CPU.Build.0 = Release|Any CPU
{8FC3E08E-8CEF-4D9A-9013-0B6AFE1BB05B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{8FC3E08E-8CEF-4D9A-9013-0B6AFE1BB05B}.Debug|Any CPU.Build.0 = Debug|Any CPU
{8FC3E08E-8CEF-4D9A-9013-0B6AFE1BB05B}.Release|Any CPU.ActiveCfg = Release|Any CPU
{8FC3E08E-8CEF-4D9A-9013-0B6AFE1BB05B}.Release|Any CPU.Build.0 = Release|Any CPU
{49669F3F-A5E4-4ABD-8CAE-C14E9D5C70B3}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{49669F3F-A5E4-4ABD-8CAE-C14E9D5C70B3}.Debug|Any CPU.Build.0 = Debug|Any CPU
{49669F3F-A5E4-4ABD-8CAE-C14E9D5C70B3}.Release|Any CPU.ActiveCfg = Release|Any CPU
{49669F3F-A5E4-4ABD-8CAE-C14E9D5C70B3}.Release|Any CPU.Build.0 = Release|Any CPU
{E022414D-36D8-436A-A66A-BEE337FEA712}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{E022414D-36D8-436A-A66A-BEE337FEA712}.Debug|Any CPU.Build.0 = Debug|Any CPU
{E022414D-36D8-436A-A66A-BEE337FEA712}.Release|Any CPU.ActiveCfg = Release|Any CPU
{E022414D-36D8-436A-A66A-BEE337FEA712}.Release|Any CPU.Build.0 = Release|Any CPU
{67CEEED4-72DA-4B09-93CE-D4313E3F410D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{67CEEED4-72DA-4B09-93CE-D4313E3F410D}.Debug|Any CPU.Build.0 = Debug|Any CPU
{67CEEED4-72DA-4B09-93CE-D4313E3F410D}.Release|Any CPU.ActiveCfg = Release|Any CPU
{67CEEED4-72DA-4B09-93CE-D4313E3F410D}.Release|Any CPU.Build.0 = Release|Any CPU
{A92E70F9-8028-4E0C-B167-884E1E56854F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{A92E70F9-8028-4E0C-B167-884E1E56854F}.Debug|Any CPU.Build.0 = Debug|Any CPU
{A92E70F9-8028-4E0C-B167-884E1E56854F}.Release|Any CPU.ActiveCfg = Release|Any CPU
Expand Down Expand Up @@ -289,6 +320,12 @@ Global
{6B9357F7-014F-4725-AF3E-0B8EA17B62C5} = {561CEB82-3D97-49D0-932E-664E6779FC61}
{E4E93A24-0A97-419F-836C-EAA23D0FFF81} = {561CEB82-3D97-49D0-932E-664E6779FC61}
{F6A9CC5C-91A2-4AAB-AEC9-8007A62A081E} = {561CEB82-3D97-49D0-932E-664E6779FC61}
{DFF1D3F3-31D3-44EA-ADB9-4BD7F7AF626D} = {414151D4-7009-4E78-A5C6-D99EBD1E67D1}
{8FC3E08E-8CEF-4D9A-9013-0B6AFE1BB05B} = {899F0713-7FC6-4750-BAFC-AC650B35B453}
{89330EB0-DD97-43F1-93AE-8CAAD820F3D5} = {8519CC01-1370-47C8-AD94-B0F326B1563F}
{49669F3F-A5E4-4ABD-8CAE-C14E9D5C70B3} = {89330EB0-DD97-43F1-93AE-8CAAD820F3D5}
{E022414D-36D8-436A-A66A-BEE337FEA712} = {89330EB0-DD97-43F1-93AE-8CAAD820F3D5}
{67CEEED4-72DA-4B09-93CE-D4313E3F410D} = {89330EB0-DD97-43F1-93AE-8CAAD820F3D5}
{B63EBC68-9A38-41C0-826E-95CD14B067A4} = {8519CC01-1370-47C8-AD94-B0F326B1563F}
{A92E70F9-8028-4E0C-B167-884E1E56854F} = {899F0713-7FC6-4750-BAFC-AC650B35B453}
{259D0D48-C856-47C8-8014-66CE9A7C353F} = {414151D4-7009-4E78-A5C6-D99EBD1E67D1}
Expand Down
5 changes: 5 additions & 0 deletions Directory.Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,13 @@
<PackageVersion Include="Aspire.Hosting" Version="$(AspireVersion)" />
<PackageVersion Include="Aspire.Hosting.AppHost" Version="$(AspireVersion)" />
<PackageVersion Include="Aspire.Hosting.NodeJS" Version="$(AspireVersion)" />
<PackageVersion Include="Aspire.Hosting.PostgreSQL" Version="8.2.2" />
<PackageVersion Include="JsonSchema.Net" Version="7.2.3" />
<!-- AspNetCore packages -->
<PackageVersion Include="Microsoft.AspNetCore.OpenApi" Version="$(AspNetCoreVersion)" />
<PackageVersion Include="Microsoft.Extensions.Configuration.Binder" Version="8.0.2" />
<PackageVersion Include="Microsoft.Extensions.Hosting.Abstractions" Version="8.0.1" />
<PackageVersion Include="AspNetCore.HealthChecks.NpgSql" Version="8.0.2" />
<PackageVersion Include="Swashbuckle.AspNetCore" Version="6.9.0" />
<!-- .NET packages -->
<PackageVersion Include="Microsoft.Extensions.Http.Resilience" Version="8.10.0" />
Expand All @@ -36,12 +38,15 @@
<PackageVersion Include="xunit.runner.visualstudio" Version="2.8.2" />
<PackageVersion Include="xunit.extensibility.execution" Version="2.9.2" />
<PackageVersion Include="Microsoft.DotNet.XUnitExtensions" Version="8.0.0-beta.24516.1" />
<PackageVersion Include="Microsoft.DotNet.RemoteExecutor" Version="8.0.0-beta.24516.1" />
<!-- External packages -->
<PackageVersion Include="OllamaSharp" Version="3.0.15" />
<PackageVersion Include="MeiliSearch" Version="0.15.3" />
<PackageVersion Include="Marten" Version="7.29.0" />
<!-- Build dependencies -->
<PackageVersion Include="Microsoft.CodeAnalysis.PublicApiAnalyzers" Version="3.3.4" />
<!-- Testcontainers packages -->
<PackageVersion Include="Testcontainers" Version="$(TestContainersVersion)" />
<PackageVersion Include="Testcontainers.PostgreSql" Version="$(TestContainersVersion)" />
</ItemGroup>
</Project>
3 changes: 3 additions & 0 deletions docs/diagnostics.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,6 @@ In these cases, refer to the `<remarks>` docs section of the API for more inform

Once a release of .NET Aspire with that API is available, the API in the .NET Aspire Community Toolkit will be marked as obsolete and will be removed in a future release.

## CTASPIREMARTEN001

The `CommunityToolkit.Aspire.Marten` package may introduce significant or breaking changes in its feature versions, as it does not encompass all `Marten` functionalities, including features like `AsyncDaemon`.
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<Project Sdk="Microsoft.NET.Sdk.Web">

<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
</PropertyGroup>

<ItemGroup>
<ProjectReference Include="..\..\..\src\CommunityToolkit.Aspire.Marten\CommunityToolkit.Aspire.Marten.csproj" />
<ProjectReference Include="..\CommunityToolkit.Aspire.Marten.ServiceDefaults\CommunityToolkit.Aspire.Marten.ServiceDefaults.csproj" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
namespace CommunityToolkit.Aspire.Marten.ApiService;

public class Movie
{
public string? Id { get; set; }
public string? Title { get; set; }
public List<string>? Genres { get; set; }
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
using CommunityToolkit.Aspire.Marten.ApiService;
using Marten;
using Marten.Services;

#pragma warning disable CTASPIREMARTEN001

var builder = WebApplication.CreateBuilder(args);

builder.AddServiceDefaults();

builder.AddMartenClient("postgres", configureStoreOptions: (storeOptions) =>
{
storeOptions.OpenTelemetry.TrackConnections = TrackLevel.Verbose;

storeOptions.OpenTelemetry.TrackEventCounters();
});

var app = builder.Build();

app.MapDefaultEndpoints();

app.MapGet("/create", async (DocumentStore documentStore) =>
{
using var session = documentStore.LightweightSession();

var documents = new Movie[] {
new() { Id = "1", Title = "Carol", Genres = ["Romance", "Drama"] },
new() { Id = "2", Title = "Wonder Woman", Genres = ["Action", "Adventure"] },
new() { Id = "3", Title = "Life of Pi", Genres = ["Adventure", "Drama"] },
new() { Id = "4", Title = "Mad Max: Fury Road", Genres = ["Adventure", "Science Fiction"] },
new() { Id = "5", Title = "Moana", Genres = ["Fantasy", "Action"] },
new() { Id = "6", Title = "Philadelphia", Genres = ["Drama"] }
};

session.Store<Movie>(documents);
await session.SaveChangesAsync();
});

app.MapGet("/get", async (DocumentStore documentStore) =>
{
using var session = documentStore.QuerySession();

var data = await session.Query<Movie>()
.ToListAsync();

return data;
});

app.Run();
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
{
"$schema": "http://json.schemastore.org/launchsettings.json",
"iisSettings": {
"windowsAuthentication": false,
"anonymousAuthentication": true,
"iisExpress": {
"applicationUrl": "http://localhost:44703",
"sslPort": 44332
}
},
"profiles": {
"http": {
"commandName": "Project",
"dotnetRunMessages": true,
"launchBrowser": true,
"applicationUrl": "http://localhost:5038",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
},
"https": {
"commandName": "Project",
"dotnetRunMessages": true,
"launchBrowser": true,
"applicationUrl": "https://localhost:7061;http://localhost:5038",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
},
"IIS Express": {
"commandName": "IISExpress",
"launchBrowser": true,
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft.AspNetCore": "Warning"
}
},
"AllowedHosts": "*"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<IsAspireHost>true</IsAspireHost>
<UserSecretsId>1fa0b68a-1f54-478f-858a-af0982b87863</UserSecretsId>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Aspire.Hosting.AppHost" />
<PackageReference Include="Aspire.Hosting.PostgreSQL" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\CommunityToolkit.Aspire.Marten.ApiService\CommunityToolkit.Aspire.Marten.ApiService.csproj" />
</ItemGroup>

</Project>
10 changes: 10 additions & 0 deletions examples/marten/CommunityToolkit.Aspire.Marten.AppHost/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
var builder = DistributedApplication.CreateBuilder(args);

var postgres = builder.AddPostgres("pg");
var db = postgres.AddDatabase("postgres");

builder.AddProject<Projects.CommunityToolkit_Aspire_Marten_ApiService>("communitytoolkit-aspire-marten-apiservice")
.WithReference(db);


builder.Build().Run();
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
{
"$schema": "https://json.schemastore.org/launchsettings.json",
"profiles": {
"https": {
"commandName": "Project",
"dotnetRunMessages": true,
"launchBrowser": true,
"applicationUrl": "https://localhost:17095;http://localhost:15105",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development",
"DOTNET_ENVIRONMENT": "Development",
"DOTNET_DASHBOARD_OTLP_ENDPOINT_URL": "https://localhost:21279",
"DOTNET_RESOURCE_SERVICE_ENDPOINT_URL": "https://localhost:22168"
}
},
"http": {
"commandName": "Project",
"dotnetRunMessages": true,
"launchBrowser": true,
"applicationUrl": "http://localhost:15105",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development",
"DOTNET_ENVIRONMENT": "Development",
"DOTNET_DASHBOARD_OTLP_ENDPOINT_URL": "http://localhost:19184",
"DOTNET_RESOURCE_SERVICE_ENDPOINT_URL": "http://localhost:20278"
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft.AspNetCore": "Warning",
"Aspire.Hosting.Dcp": "Warning"
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<IsAspireSharedProject>true</IsAspireSharedProject>
</PropertyGroup>

<ItemGroup>
<FrameworkReference Include="Microsoft.AspNetCore.App" />

<PackageReference Include="Microsoft.Extensions.Http.Resilience" />
<PackageReference Include="Microsoft.Extensions.ServiceDiscovery" />
<PackageReference Include="OpenTelemetry.Exporter.OpenTelemetryProtocol" />
<PackageReference Include="OpenTelemetry.Extensions.Hosting" />
<PackageReference Include="OpenTelemetry.Instrumentation.AspNetCore" />
<PackageReference Include="OpenTelemetry.Instrumentation.Http" />
<PackageReference Include="OpenTelemetry.Instrumentation.Runtime" />
</ItemGroup>

</Project>
Loading