Skip to content

Commit

Permalink
更新版本号,添加新项目和接口实现
Browse files Browse the repository at this point in the history
更新了 `Directory.Build.props` 文件中的版本号,从 `1.0.7` 更新到 `1.0.8`,并为 `net9.0` 框架添加了 `MicrosoftAspNetCorePackageVersion` 版本号 `9.0.0`。
在 `Gnarly.sln` 解决方案文件中,添加了 `Gnarly.Test` 项目,并更新了相应的项目配置。
新增了 `Gnarly.Test.csproj` 项目文件,目标框架为 `net8.0`,并启用了隐式使用和可空引用类型。
新增了 `ITest2Service.cs` 文件,定义了 `ITest2Service` 接口。
新增了 `Test2Service.cs` 文件,实现了 `ITest2Service` 和 `IScopeDependency` 接口。
更新了 `Gnarly.WebApi.csproj` 文件,设置了 `IsPackable` 和 `GeneratePackageOnBuild` 属性为 `true`,并添加了对 `Gnarly.Test` 项目的引用。
在 `Program.cs` 文件中,移除了 `builder.Services.AddAutoGnarly();` 这一行代码。
在 `ServiceRegistrationGenerator.cs` 文件中,添加了 `using System.Diagnostics;` 引用,并更新了命名空间,将 `namespace System` 修改为 `namespace {compilation.AssemblyName}`。
  • Loading branch information
239573049 committed Dec 15, 2024
1 parent c6820d5 commit 877496a
Show file tree
Hide file tree
Showing 9 changed files with 44 additions and 6 deletions.
3 changes: 2 additions & 1 deletion Directory.Build.props
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
<Project>

<PropertyGroup>
<Version>1.0.7</Version>
<Version>1.1.0</Version>
<Company>AIDotNet</Company>
<Authors>Token</Authors>
<Description>自动依赖注入,利用源生成器实现自动依赖注入,并且不使用反射进行实现功能。</Description>
<PackageProjectUrl>https://github.com/AIDotNet/Gnarly</PackageProjectUrl>
<PackageLicenseExpression>MIT</PackageLicenseExpression>
<RepositoryUrl>https://github.com/AIDotNet/Gnarly</RepositoryUrl>
<RepositoryType>git</RepositoryType>
<MicrosoftAspNetCorePackageVersion Condition="'$(TargetFramework)' == 'net9.0'">9.0.0</MicrosoftAspNetCorePackageVersion>
<MicrosoftAspNetCorePackageVersion Condition="'$(TargetFramework)' == 'net8.0'">8.0.0</MicrosoftAspNetCorePackageVersion>
<MicrosoftAspNetCorePackageVersion Condition="'$(TargetFramework)' == 'net7.0'">7.0.0</MicrosoftAspNetCorePackageVersion>
<MicrosoftAspNetCorePackageVersion Condition="'$(TargetFramework)' == 'net6.0'">6.0.0</MicrosoftAspNetCorePackageVersion>
Expand Down
7 changes: 7 additions & 0 deletions Gnarly.sln
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Gnarly.Application", "src\Gnarly.Application\Gnarly.Application.csproj", "{B241F5DD-1A66-4E36-9B98-C7D4A5D5A1A8}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Gnarly.Test", "src\Gnarly.Test\Gnarly.Test.csproj", "{6D10270A-6309-430B-8902-582DBA9BF8BF}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand All @@ -41,6 +43,10 @@ Global
{B241F5DD-1A66-4E36-9B98-C7D4A5D5A1A8}.Debug|Any CPU.Build.0 = Debug|Any CPU
{B241F5DD-1A66-4E36-9B98-C7D4A5D5A1A8}.Release|Any CPU.ActiveCfg = Release|Any CPU
{B241F5DD-1A66-4E36-9B98-C7D4A5D5A1A8}.Release|Any CPU.Build.0 = Release|Any CPU
{6D10270A-6309-430B-8902-582DBA9BF8BF}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{6D10270A-6309-430B-8902-582DBA9BF8BF}.Debug|Any CPU.Build.0 = Debug|Any CPU
{6D10270A-6309-430B-8902-582DBA9BF8BF}.Release|Any CPU.ActiveCfg = Release|Any CPU
{6D10270A-6309-430B-8902-582DBA9BF8BF}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand All @@ -50,6 +56,7 @@ Global
{28EE6E90-E647-4EAA-98EB-6599EBC5CE69} = {EAEBB030-5D94-4D76-98DC-C947ECE0F269}
{30E211CA-1BED-425B-8035-BEBBD47F4EE7} = {EAEBB030-5D94-4D76-98DC-C947ECE0F269}
{B241F5DD-1A66-4E36-9B98-C7D4A5D5A1A8} = {EAEBB030-5D94-4D76-98DC-C947ECE0F269}
{6D10270A-6309-430B-8902-582DBA9BF8BF} = {EAEBB030-5D94-4D76-98DC-C947ECE0F269}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {271DCA1A-7B6B-431E-A491-8C1A7B8971D9}
Expand Down
2 changes: 2 additions & 0 deletions Gnarly.sln.DotSettings.user
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
<wpf:ResourceDictionary xml:space="preserve" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:s="clr-namespace:System;assembly=mscorlib" xmlns:ss="urn:shemas-jetbrains-com:settings-storage-xaml" xmlns:wpf="http://schemas.microsoft.com/winfx/2006/xaml/presentation">
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003AGnarlyExtensions_002Eg_002Ecs_002Fl_003AC_0021_003FUsers_003F23957_003FAppData_003FLocal_003FTemp_003FSourceGeneratedDocuments_003F2F1B399F9836E5C0B41E66FA_003FGnarly_003FGnarly_002EServiceRegistrationGenerator_003FGnarlyExtensions_002Eg_002Ecs/@EntryIndexedValue">ForceIncluded</s:String></wpf:ResourceDictionary>
13 changes: 13 additions & 0 deletions src/Gnarly.Test/Gnarly.Test.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<Project Sdk="Microsoft.NET.Sdk">

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

<ItemGroup>
<ProjectReference Include="..\Gnarly.Data\Gnarly.Data.csproj" />
</ItemGroup>

</Project>
6 changes: 6 additions & 0 deletions src/Gnarly.Test/ITest2Service.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
namespace Gnarly.Test;

public interface ITest2Service
{

}
7 changes: 7 additions & 0 deletions src/Gnarly.Test/Test2Service.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
using Gnarly.Data;

namespace Gnarly.Test;

public class Test2Service : ITest2Service, IScopeDependency
{
}
3 changes: 3 additions & 0 deletions src/Gnarly.WebApi/Gnarly.WebApi.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
<DockerDefaultTargetOS>Linux</DockerDefaultTargetOS>
<IsPackable>true</IsPackable>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
</PropertyGroup>

<ItemGroup>
Expand All @@ -13,6 +15,7 @@

<ItemGroup>
<ProjectReference Include="..\Gnarly.Application\Gnarly.Application.csproj" />
<ProjectReference Include="..\Gnarly.Test\Gnarly.Test.csproj" />
<ProjectReference Include="..\Gnarly\Gnarly.csproj">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
Expand Down
1 change: 0 additions & 1 deletion src/Gnarly.WebApi/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ private static void Main(string[] args)

builder.Services.AddEndpointsApiExplorer();
builder.Services.AddSwaggerGen();
builder.Services.AddAutoGnarly();

var app = builder.Build();

Expand Down
8 changes: 4 additions & 4 deletions src/Gnarly/ServiceRegistrationGenerator.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;
using Microsoft.CodeAnalysis;
Expand All @@ -22,7 +23,6 @@ private void Execute(Compilation compilation, SourceProductionContext context)
var singletonMethods = new List<string>();
var transientMethods = new List<string>();

// 扫描当前编译单元和所有引用的程序集
ScanService.ScanAndCollect(compilation, scopeMethods, singletonMethods, transientMethods);

var scopeRegistrations = string.Join("\n ", scopeMethods.Select(m => $"services.AddScoped<{m}>();"));
Expand All @@ -36,9 +36,9 @@ private void Execute(Compilation compilation, SourceProductionContext context)
using System;
using Microsoft.Extensions.DependencyInjection;
namespace System
namespace {compilation.AssemblyName}
{{
public static class GnarlyExtensions
public static class {compilation.AssemblyName?.Replace(".","")}Extensions
{{
/// <summary>
/// SourceGenerator自动注入服务
Expand All @@ -57,7 +57,7 @@ public static IServiceCollection AddAutoGnarly(this IServiceCollection services)
";

// 添加生成的源代码到编译单元
context.AddSource($"GnarlyExtensions.g.cs", SourceText.From(source, Encoding.UTF8));
context.AddSource($"{compilation.AssemblyName?.Replace(".", "")}Extensions.g.cs", SourceText.From(source, Encoding.UTF8));
}

private string GetDebuggerDisplay()
Expand Down

0 comments on commit 877496a

Please sign in to comment.