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 12 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
46 changes: 42 additions & 4 deletions CommunityToolkit.Aspire.sln
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{414151D4-700
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "CommunityToolkit.Aspire.Hosting.Java", "src\CommunityToolkit.Aspire.Hosting.Java\CommunityToolkit.Aspire.Hosting.Java.csproj", "{DAA67050-44B3-458F-9818-5877D606866A}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CommunityToolkit.Aspire.Hosting.Azure.StaticWebApps", "src\CommunityToolkit.Aspire.Hosting.Azure.StaticWebApps\CommunityToolkit.Aspire.Hosting.Azure.StaticWebApps.csproj", "{125DFA83-328D-4F8B-91EC-3057FFF410BE}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "CommunityToolkit.Aspire.Hosting.Azure.StaticWebApps", "src\CommunityToolkit.Aspire.Hosting.Azure.StaticWebApps\CommunityToolkit.Aspire.Hosting.Azure.StaticWebApps.csproj", "{125DFA83-328D-4F8B-91EC-3057FFF410BE}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "examples", "examples", "{8519CC01-1370-47C8-AD94-B0F326B1563F}"
EndProject
Expand Down Expand Up @@ -77,16 +77,28 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "CommunityToolkit.Aspire.Oll
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "CommunityToolkit.Aspire.Hosting.Meilisearch.Tests", "tests\CommunityToolkit.Aspire.Hosting.Meilisearch\CommunityToolkit.Aspire.Hosting.Meilisearch.Tests.csproj", "{C715669D-FBDE-4BFF-B9A3-75615D3C179A}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CommunityToolkit.Aspire.Meilisearch.Tests", "tests\CommunityToolkit.Aspire.Meilisearch.Tests\CommunityToolkit.Aspire.Meilisearch.Tests.csproj", "{0AACC135-9624-423D-8988-69701C0FE428}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "CommunityToolkit.Aspire.Meilisearch.Tests", "tests\CommunityToolkit.Aspire.Meilisearch.Tests\CommunityToolkit.Aspire.Meilisearch.Tests.csproj", "{0AACC135-9624-423D-8988-69701C0FE428}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "meilisearch", "meilisearch", "{561CEB82-3D97-49D0-932E-664E6779FC61}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CommunityToolkit.Aspire.Hosting.Meilisearch.AppHost", "examples\meilisearch\CommunityToolkit.Aspire.Hosting.Meilisearch.AppHost\CommunityToolkit.Aspire.Hosting.Meilisearch.AppHost.csproj", "{6B9357F7-014F-4725-AF3E-0B8EA17B62C5}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "CommunityToolkit.Aspire.Hosting.Meilisearch.AppHost", "examples\meilisearch\CommunityToolkit.Aspire.Hosting.Meilisearch.AppHost\CommunityToolkit.Aspire.Hosting.Meilisearch.AppHost.csproj", "{6B9357F7-014F-4725-AF3E-0B8EA17B62C5}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CommunityToolkit.Aspire.Hosting.Meilisearch.ServiceDefaults", "examples\meilisearch\CommunityToolkit.Aspire.Hosting.Meilisearch.ServiceDefaults\CommunityToolkit.Aspire.Hosting.Meilisearch.ServiceDefaults.csproj", "{E4E93A24-0A97-419F-836C-EAA23D0FFF81}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "CommunityToolkit.Aspire.Hosting.Meilisearch.ServiceDefaults", "examples\meilisearch\CommunityToolkit.Aspire.Hosting.Meilisearch.ServiceDefaults\CommunityToolkit.Aspire.Hosting.Meilisearch.ServiceDefaults.csproj", "{E4E93A24-0A97-419F-836C-EAA23D0FFF81}"
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}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -225,6 +237,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
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down Expand Up @@ -269,6 +301,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}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {08B1D4B8-D2C5-4A64-BB8B-E1A2B29525F0}
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>
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