Skip to content

Commit 2d3d153

Browse files
committed
Move some stuff around and add gen projects
1 parent 34caf62 commit 2d3d153

File tree

78 files changed

+902
-167
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

78 files changed

+902
-167
lines changed

AStar.Dev.slnx

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@
3939
</Folder>
4040
<Folder Name="/src/modules/usage module/">
4141
<Project Path="src/nuget-packages/AStar.Dev.Api.Usage.Sdk/AStar.Dev.Api.Usage.Sdk.csproj" />
42-
<Project Path="src\nuget-packages\AStar.Dev.Usage.Api.Client.SDK\AStar.Dev.Usage.Api.Client.SDK.csproj" Type="C#" />
42+
<Project Path="src/nuget-packages/AStar.Dev.Usage.Api.Client.SDK/AStar.Dev.Usage.Api.Client.SDK.csproj" Type="C#" />
4343
</Folder>
4444
<Folder Name="/src/nuget-packages/">
4545
<Project Path="src/nuget-packages/AStar.Dev.Api.HealthChecks/AStar.Dev.Api.HealthChecks.csproj" />
@@ -63,8 +63,9 @@
6363
<Project Path="src/nuget-packages/AStar.Dev.Utilities/AStar.Dev.Utilities.csproj" />
6464
</Folder>
6565
<Folder Name="/src/source-generators/">
66-
<Project Path="src/source-generators/AStar.Dev.SourceGenerators/AStar.Dev.SourceGenerators.csproj" />
6766
<Project Path="src\source-generators\AStar.Dev.Annotations\AStar.Dev.Annotations.csproj" Type="Classic C#" />
67+
<Project Path="src\source-generators\AStar.Dev.SourceGenerators.TestApp\AStar.Dev.SourceGenerators.TestApp.csproj" Type="Classic C#" />
68+
<Project Path="src\source-generators\AStar.Dev.SourceGenerators\AStar.Dev.SourceGenerators.csproj" Type="Classic C#" />
6869
</Folder>
6970
<Folder Name="/src/uis/">
7071
<Project Path="src/uis/AStar.Dev.Web/AStar.Dev.Web.csproj" />
@@ -78,9 +79,9 @@
7879
<Project Path="test/AStar.Dev.Tests.Architecture/AStar.Dev.Tests.Architecture.csproj" />
7980
</Folder>
8081
<Folder Name="/test/modules/">
81-
<Project Path="test/modules/AStar.Dev.Database.Updater.Core.Tests.Unit/AStar.Dev.Database.Updater.Core.Tests.Unit.csproj" />
8282
<Project Path="test/modules/AStar.Dev.Database.Updater.Tests.Integration/AStar.Dev.Database.Updater.Tests.Integration.csproj" />
8383
<Project Path="test/modules/AStar.Dev.Database.Updater.Tests.Unit/AStar.Dev.Database.Updater.Tests.Unit.csproj" />
84+
<Project Path="test\modules\AStar.Dev.Database.Updater.Core.Tests.Integration\AStar.Dev.Database.Updater.Core.Tests.Integration.csproj" />
8485
</Folder>
8586
<Folder Name="/test/modules/apis/">
8687
<Project Path="test/modules/apis/AStar.Dev.Admin.Api.Tests.EndToEnd/AStar.Dev.Admin.Api.Tests.EndToEnd.csproj" />
Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
1-
<Project Sdk="Microsoft.NET.Sdk">
2-
1+
<Project Sdk="Microsoft.NET.Sdk">
32
<PropertyGroup>
43
<TargetFramework>netstandard2.0</TargetFramework>
54
<LangVersion>preview</LangVersion>
65
<Nullable>enable</Nullable>
76
<ImplicitUsings>enable</ImplicitUsings>
87
</PropertyGroup>
9-
108
</Project>
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
namespace AStar.Dev.Annotations;
2+
3+
[AttributeUsage(AttributeTargets.Class, Inherited = false)]
4+
public sealed class ConfigSectionAttribute(string name) : Attribute
5+
{
6+
public string Name { get; } = name;
7+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
namespace AStar.Dev.Annotations;
2+
3+
[AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct)]
4+
public sealed class MapFromAttribute(Type source) : Attribute
5+
{
6+
public Type Source { get; } = source;
7+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
namespace AStar.Dev.Annotations;
2+
3+
public enum Lifetime
4+
{
5+
Singleton,
6+
Scoped,
7+
Transient
8+
}
9+
10+
[AttributeUsage(AttributeTargets.Class, Inherited = false)]
11+
public sealed class ServiceAttribute(Lifetime lifetime = Lifetime.Scoped) : Attribute
12+
{
13+
// Positional: choose lifetime (default Scoped)
14+
public Lifetime Lifetime { get; } = lifetime;
15+
16+
// Named: override the service interface to register against
17+
public Type? As { get; set; }
18+
19+
// Named: also register the concrete type as itself (optional)
20+
public bool AsSelf { get; set; } = false;
21+
}
Lines changed: 5 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,11 @@
1-
using System;
2-
31
namespace AStar.Dev.Annotations;
42

5-
/// <summary>
6-
/// Represents an attribute that can be used to mark a struct as a strong identifier.
7-
/// </summary>
8-
/// <remarks>
9-
/// This attribute is used to annotate structures with a specific identifier type, typically
10-
/// to signify that the struct is a strongly typed id. The default identifier type is a GUID.
11-
/// </remarks>
12-
/// <param name="idType">
13-
/// The type of the identifier associated with the struct. By default, it is "System.Guid".
14-
/// </param>
15-
/// <param name="guidV7">
16-
/// Indicates whether the GUID used as the identifier for the struct conforms to the version 7 GUID format.
17-
/// </param>
183
[AttributeUsage(AttributeTargets.Struct)]
19-
public sealed class StrongIdAttribute(string idType = "System.Guid", bool guidV7 = true) : Attribute
4+
public sealed class StrongIdAttribute(string underlying = "System.Guid") : Attribute
205
{
216
/// <summary>
22-
/// Gets the type of the identifier associated with a struct marked by the <see cref="StrongIdAttribute"/>.
23-
/// </summary>
24-
/// <remarks>
25-
/// This property returns the string name of the identifier type. By default, it is "System.Guid".
26-
/// The identifier type specifies the type used as an identifier for the struct.
27-
/// </remarks>
28-
public string IdType { get; } = idType;
29-
30-
/// <summary>
31-
/// Indicates whether the GUID used as the identifier for a struct marked by the <see cref="StrongIdAttribute"/>
32-
/// conforms to the version 7 GUID format.
7+
/// Underlying CLR type. Defaults to System.Guid.
8+
/// Examples: "System.Guid", "int", "long", "string".
339
/// </summary>
34-
/// <remarks>
35-
/// Version 7 GUIDs are designed to facilitate time-based sorting and are a newer standard
36-
/// compared to the traditional random GUIDs (version 4). When this property is set to true,
37-
/// the identifier adopts the version 7 format.
38-
/// </remarks>
39-
public bool GuidV7 { get; } = guidV7;
40-
}
10+
public string Underlying { get; } = underlying;
11+
}
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
<PropertyGroup>
3+
<OutputType>Exe</OutputType>
4+
<TargetFramework>net9.0</TargetFramework>
5+
<Nullable>enable</Nullable>
6+
<ImplicitUsings>enable</ImplicitUsings>
7+
<EmitCompilerGeneratedFiles>true</EmitCompilerGeneratedFiles>
8+
<!-- <CompilerGeneratedFilesOutputPath>.\GeneratedFiles</CompilerGeneratedFilesOutputPath> -->
9+
</PropertyGroup>
10+
11+
<ItemGroup>
12+
<!-- Source generator wired in as an analyzer -->
13+
<ProjectReference Include="..\AStar.Dev.Annotations\AStar.Dev.Annotations.csproj" />
14+
<ProjectReference Include="..\AStar.Dev.SourceGenerators\AStar.Dev.SourceGenerators.csproj" OutputItemType="Analyzer" ReferenceOutputAssembly="false" />
15+
</ItemGroup>
16+
17+
<ItemGroup>
18+
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="9.0.10"/>
19+
<PackageReference Include="Microsoft.Extensions.Configuration" Version="9.0.10"/>
20+
<PackageReference Include="Microsoft.Extensions.Configuration.EnvironmentVariables" Version="9.0.10"/>
21+
<PackageReference Include="Microsoft.Extensions.Configuration.Binder" Version="9.0.10"/>
22+
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="9.0.10"/>
23+
<PackageReference Include="Microsoft.Extensions.Options.ConfigurationExtensions" Version="9.0.10"/>
24+
</ItemGroup>
25+
26+
<ItemGroup>
27+
<AdditionalFiles Include="options.schema"/>
28+
</ItemGroup>
29+
30+
<ItemGroup>
31+
<None Include="appsettings.json">
32+
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
33+
</None>
34+
</ItemGroup>
35+
</Project>
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
using AStar.Dev.Annotations;
2+
3+
namespace AStar.Dev.SourceGenerators.TestApp;
4+
5+
[StrongId]
6+
public readonly partial struct OrderId;
7+
8+
public sealed class Order
9+
{
10+
public OrderId Id { get; set; }
11+
public string Status { get; set; } = "";
12+
public int Quantity { get; set; }
13+
public string? Note { get; set; }
14+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
using AStar.Dev.Annotations;
2+
3+
namespace AStar.Dev.SourceGenerators.TestApp;
4+
5+
[MapFrom(typeof(Order))]
6+
public sealed class OrderDto
7+
{
8+
public OrderId Id { get; set; } // same type → direct assign
9+
public string Status { get; set; } = "";
10+
public int Quantity { get; set; }
11+
public string? Note { get; set; } // no source → generator will DIAGNOSE
12+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
using System.ComponentModel.DataAnnotations;
2+
using AStar.Dev.Annotations;
3+
4+
namespace AStar.Dev.SourceGenerators.TestApp;
5+
6+
[ConfigSection("Payments")]
7+
public sealed class PaymentsOptions
8+
{
9+
public string ApiKey { get; set; } = default!;
10+
11+
[Range(1, 120)] public int TimeoutSeconds { get; set; }
12+
}

0 commit comments

Comments
 (0)