Skip to content

Commit 84693d7

Browse files
committed
Feat: Import of AterraEngine.DependencyInjection
1 parent 4c6475b commit 84693d7

File tree

46 files changed

+1700
-8
lines changed

Some content is hidden

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

46 files changed

+1700
-8
lines changed

CodeOfChaos.Extensions.sln

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,15 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "examples", "examples", "{C6
3030
EndProject
3131
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Examples.CodeOfChaos.Extensions.Analyzers", "examples\Examples.CodeOfChaos.Extensions.Analyzers\Examples.CodeOfChaos.Extensions.Analyzers.csproj", "{50072DFE-34A3-4E93-A2A1-02CDDCA66CBE}"
3232
EndProject
33-
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "analyzers", "analyzers", "{9F807E1D-D361-4CAB-8FD2-39B8A4F7AFFF}"
33+
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Roslyn", "Roslyn", "{9F807E1D-D361-4CAB-8FD2-39B8A4F7AFFF}"
34+
EndProject
35+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Tests.CodeOfChaos.Extensions.DependencyInjection", "tests\Tests.CodeOfChaos.Extensions.DependencyInjection\Tests.CodeOfChaos.Extensions.DependencyInjection.csproj", "{A0C53C66-FFEC-42EF-A1CD-4E7396DB74FA}"
36+
EndProject
37+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Tests.CodeOfChaos.Extensions.DependencyInjection.Generators", "tests\Tests.CodeOfChaos.Extensions.DependencyInjection.Generators\Tests.CodeOfChaos.Extensions.DependencyInjection.Generators.csproj", "{77E466A0-F307-4452-8CBC-A541FC27F4BF}"
38+
EndProject
39+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CodeOfChaos.Extensions.DependencyInjection", "src\CodeOfChaos.Extensions.DependencyInjection\CodeOfChaos.Extensions.DependencyInjection.csproj", "{9B1053FC-89D7-412D-AA24-618EFC97FDA4}"
40+
EndProject
41+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CodeOfChaos.Extensions.DependencyInjection.Generators", "src\CodeOfChaos.Extensions.DependencyInjection.Generators\CodeOfChaos.Extensions.DependencyInjection.Generators.csproj", "{9FC9F294-BDB7-4479-B002-F0409E050A1E}"
3442
EndProject
3543
Global
3644
GlobalSection(SolutionConfigurationPlatforms) = preSolution
@@ -82,6 +90,22 @@ Global
8290
{50072DFE-34A3-4E93-A2A1-02CDDCA66CBE}.Debug|Any CPU.Build.0 = Debug|Any CPU
8391
{50072DFE-34A3-4E93-A2A1-02CDDCA66CBE}.Release|Any CPU.ActiveCfg = Release|Any CPU
8492
{50072DFE-34A3-4E93-A2A1-02CDDCA66CBE}.Release|Any CPU.Build.0 = Release|Any CPU
93+
{A0C53C66-FFEC-42EF-A1CD-4E7396DB74FA}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
94+
{A0C53C66-FFEC-42EF-A1CD-4E7396DB74FA}.Debug|Any CPU.Build.0 = Debug|Any CPU
95+
{A0C53C66-FFEC-42EF-A1CD-4E7396DB74FA}.Release|Any CPU.ActiveCfg = Release|Any CPU
96+
{A0C53C66-FFEC-42EF-A1CD-4E7396DB74FA}.Release|Any CPU.Build.0 = Release|Any CPU
97+
{77E466A0-F307-4452-8CBC-A541FC27F4BF}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
98+
{77E466A0-F307-4452-8CBC-A541FC27F4BF}.Debug|Any CPU.Build.0 = Debug|Any CPU
99+
{77E466A0-F307-4452-8CBC-A541FC27F4BF}.Release|Any CPU.ActiveCfg = Release|Any CPU
100+
{77E466A0-F307-4452-8CBC-A541FC27F4BF}.Release|Any CPU.Build.0 = Release|Any CPU
101+
{9B1053FC-89D7-412D-AA24-618EFC97FDA4}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
102+
{9B1053FC-89D7-412D-AA24-618EFC97FDA4}.Debug|Any CPU.Build.0 = Debug|Any CPU
103+
{9B1053FC-89D7-412D-AA24-618EFC97FDA4}.Release|Any CPU.ActiveCfg = Release|Any CPU
104+
{9B1053FC-89D7-412D-AA24-618EFC97FDA4}.Release|Any CPU.Build.0 = Release|Any CPU
105+
{9FC9F294-BDB7-4479-B002-F0409E050A1E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
106+
{9FC9F294-BDB7-4479-B002-F0409E050A1E}.Debug|Any CPU.Build.0 = Debug|Any CPU
107+
{9FC9F294-BDB7-4479-B002-F0409E050A1E}.Release|Any CPU.ActiveCfg = Release|Any CPU
108+
{9FC9F294-BDB7-4479-B002-F0409E050A1E}.Release|Any CPU.Build.0 = Release|Any CPU
85109
EndGlobalSection
86110
GlobalSection(NestedProjects) = preSolution
87111
{26284571-0E09-4BAF-8C2B-DF87DCC1BA0B} = {8DD280D4-1E14-4D5E-AFE6-58DD8F079DCC}
@@ -96,5 +120,9 @@ Global
96120
{50072DFE-34A3-4E93-A2A1-02CDDCA66CBE} = {C632855B-76D1-4D5E-9A0A-E631B5FE71A2}
97121
{9F807E1D-D361-4CAB-8FD2-39B8A4F7AFFF} = {197E72AD-DEAB-4350-AFC3-A3BB38720BF5}
98122
{E9BB7403-5167-46CA-BE84-F420CF28C910} = {9F807E1D-D361-4CAB-8FD2-39B8A4F7AFFF}
123+
{A0C53C66-FFEC-42EF-A1CD-4E7396DB74FA} = {8DD280D4-1E14-4D5E-AFE6-58DD8F079DCC}
124+
{77E466A0-F307-4452-8CBC-A541FC27F4BF} = {8DD280D4-1E14-4D5E-AFE6-58DD8F079DCC}
125+
{9B1053FC-89D7-412D-AA24-618EFC97FDA4} = {197E72AD-DEAB-4350-AFC3-A3BB38720BF5}
126+
{9FC9F294-BDB7-4479-B002-F0409E050A1E} = {9F807E1D-D361-4CAB-8FD2-39B8A4F7AFFF}
99127
EndGlobalSection
100128
EndGlobal
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<TargetFramework>net9.0</TargetFramework>
5+
<Nullable>enable</Nullable>
6+
</PropertyGroup>
7+
8+
<ItemGroup>
9+
<ProjectReference Include="..\AterraEngine.DependencyInjection.Generators\AterraEngine.DependencyInjection.Generators.csproj" OutputItemType="Analyzer" ReferenceOutputAssembly="false"/>
10+
<ProjectReference Include="..\AterraEngine.DependencyInjection\AterraEngine.DependencyInjection.csproj"/>
11+
</ItemGroup>
12+
13+
<ItemGroup>
14+
<None Remove="DDD.UbiquitousLanguageRegistry.txt"/>
15+
</ItemGroup>
16+
17+
<ItemGroup>
18+
<PackageReference Include="Microsoft.Extensions.ObjectPool" Version="9.0.0"/>
19+
<PackageReference Include="System.Buffers" Version="4.6.0"/>
20+
</ItemGroup>
21+
22+
</Project>
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
// ---------------------------------------------------------------------------------------------------------------------
2+
// Imports
3+
// ---------------------------------------------------------------------------------------------------------------------
4+
using Microsoft.Extensions.DependencyInjection;
5+
6+
namespace AterraEngine.DependencyInjection.Generators.Sample;
7+
// ---------------------------------------------------------------------------------------------------------------------
8+
// Code
9+
// ---------------------------------------------------------------------------------------------------------------------
10+
[InjectableService<IExampleService>(ServiceLifetime.Singleton)]
11+
public class ExampleService : IExampleService;
12+
13+
public interface IExampleService;
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
// ---------------------------------------------------------------------------------------------------------------------
2+
// Imports
3+
// ---------------------------------------------------------------------------------------------------------------------
4+
using Microsoft.Extensions.DependencyInjection;
5+
6+
namespace AterraEngine.DependencyInjection.Generators.Sample;
7+
// ---------------------------------------------------------------------------------------------------------------------
8+
// Code
9+
// ---------------------------------------------------------------------------------------------------------------------
10+
[FactoryCreatedService<IExampleFactory, ICreatedService>(ServiceLifetime.Transient)]
11+
public class CreatedService : ICreatedService;
12+
13+
public interface ICreatedService;
14+
15+
[InjectableService<IExampleFactory>(ServiceLifetime.Singleton)]
16+
public class ExampleFactory : IExampleFactory {
17+
public ICreatedService Create() => new CreatedService();
18+
}
19+
20+
public interface IExampleFactory : IFactoryService<ICreatedService>;
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
// ---------------------------------------------------------------------------------------------------------------------
2+
// Imports
3+
// ---------------------------------------------------------------------------------------------------------------------
4+
namespace AterraEngine.DependencyInjection.Generators.Sample;
5+
// ---------------------------------------------------------------------------------------------------------------------
6+
// Code
7+
// ---------------------------------------------------------------------------------------------------------------------
8+
[PooledInjectableService<IExamplePooled, ExamplePooled>]
9+
public class ExamplePooled : IExamplePooled {
10+
public bool Reset() => true;
11+
}
12+
13+
public interface IExamplePooled : IManualPoolable;
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// ---------------------------------------------------------------------------------------------------------------------
2+
// Imports
3+
// ---------------------------------------------------------------------------------------------------------------------
4+
using Microsoft.Extensions.DependencyInjection;
5+
6+
namespace AterraEngine.DependencyInjection.Generators.Sample;
7+
// ---------------------------------------------------------------------------------------------------------------------
8+
// Code
9+
// ---------------------------------------------------------------------------------------------------------------------
10+
// [InjectableService<ISecondDualExampleService>(ServiceLifetime.Singleton)]
11+
[InjectableService<IFirstDualExampleService>(ServiceLifetime.Singleton)]
12+
public class DualExampleService : IFirstDualExampleService, ISecondDualExampleService;
13+
14+
public interface IFirstDualExampleService;
15+
16+
public interface ISecondDualExampleService;
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
## Release 1.0
2+
3+
### New Rules
4+
5+
Rule ID | Category | Severity | Notes
6+
----------|--------------------|----------|--------------------------------------
7+
ATRDI001 | InjectableServices | Info | InjectableServiceAttribute not found
8+
ATRDI002 | SourceGenerator | Error | No assembly name was found
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
### New Rules
2+
3+
Rule ID | Category | Severity | Notes
4+
---------|----------|----------|-------
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<TargetFramework>netstandard2.0</TargetFramework>
5+
<IsPackable>false</IsPackable>
6+
<Nullable>enable</Nullable>
7+
<LangVersion>latest</LangVersion>
8+
9+
<DevelopmentDependency>true</DevelopmentDependency>
10+
<EnforceExtendedAnalyzerRules>true</EnforceExtendedAnalyzerRules>
11+
<IsRoslynComponent>true</IsRoslynComponent>
12+
13+
<IsPackable>true</IsPackable>
14+
<PackageId>CodeOfChaos.Extensions.DependencyInjection.Generators</PackageId> <!-- Main package name -->
15+
<Version>0.29.2</Version> <!-- Package version -->
16+
<Authors>Anna Sas</Authors>
17+
<Description>A small package allowing easy collection of dependency injection services</Description>
18+
<PackageProjectUrl>https://github.com/code-of-chaos/cs-code_of_chaos-extensions</PackageProjectUrl>
19+
<PackageTags>dependency injection;di</PackageTags>
20+
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
21+
<PublishRepositoryUrl>true</PublishRepositoryUrl>
22+
<IncludeSymbols>true</IncludeSymbols>
23+
<DebugType>embedded</DebugType>
24+
<PackageLicenseFile>LICENSE</PackageLicenseFile>
25+
<PackageReadmeFile>README.md</PackageReadmeFile>
26+
<PackageIcon>icon.png</PackageIcon>
27+
</PropertyGroup>
28+
29+
<ItemGroup>
30+
<None Include="../../LICENSE" Pack="true" PackagePath="" Visible="false" />
31+
<None Include="../../src/CodeOfChaos.Extensions.DependencyInjection/README.md" Pack="true" PackagePath="" />
32+
<None Include="../../assets/icon.png" Pack="true" PackagePath="" Visible="false" />
33+
</ItemGroup>
34+
35+
<ItemGroup>
36+
<PackageReference Include="Microsoft.CodeAnalysis.Analyzers" Version="3.11.0">
37+
<PrivateAssets>all</PrivateAssets>
38+
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
39+
</PackageReference>
40+
<PackageReference Include="Microsoft.CodeAnalysis.Common" Version="4.12.0" />
41+
<PackageReference Include="Microsoft.CodeAnalysis.CSharp" Version="4.12.0">
42+
<PrivateAssets>all</PrivateAssets>
43+
</PackageReference>
44+
</ItemGroup>
45+
46+
<ItemGroup>
47+
<None Include="$(OutputPath)\$(AssemblyName).dll" Pack="true" PackagePath="analyzers/dotnet/cs" Visible="false" />
48+
</ItemGroup>
49+
50+
51+
</Project>
Lines changed: 168 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,168 @@
1+
// Licensed to the .NET Foundation under one or more agreements.
2+
// The .NET Foundation licenses this file to you under the MIT license.
3+
// See the LICENSE file in the project root for more information.
4+
5+
// This was copied from https://github.com/dotnet/runtime/blob/39b9607807f29e48cae4652cd74735182b31182e/src/libraries/System.Private.CoreLib/src/System/Diagnostics/CodeAnalysis/NullableAttributes.cs
6+
// and updated to have the scope of the attributes be internal.
7+
8+
// ReSharper disable once CheckNamespace
9+
// ReSharper disable UnusedAutoPropertyAccessor.Global
10+
namespace System.Diagnostics.CodeAnalysis;
11+
#if !NETCOREAPP
12+
13+
/// <summary>Specifies that null is allowed as an input even if the corresponding type disallows it.</summary>
14+
[AttributeUsage(AttributeTargets.Field | AttributeTargets.Parameter | AttributeTargets.Property)]
15+
internal sealed class AllowNullAttribute : Attribute;
16+
17+
/// <summary>Specifies that null is disallowed as an input even if the corresponding type allows it.</summary>
18+
[AttributeUsage(AttributeTargets.Field | AttributeTargets.Parameter | AttributeTargets.Property)]
19+
internal sealed class DisallowNullAttribute : Attribute;
20+
21+
/// <summary>Specifies that an output may be null even if the corresponding type disallows it.</summary>
22+
[AttributeUsage(AttributeTargets.Field | AttributeTargets.Parameter | AttributeTargets.Property | AttributeTargets.ReturnValue)]
23+
internal sealed class MaybeNullAttribute : Attribute;
24+
25+
/// <summary>Specifies that an output will not be null even if the corresponding type allows it.</summary>
26+
[AttributeUsage(AttributeTargets.Field | AttributeTargets.Parameter | AttributeTargets.Property | AttributeTargets.ReturnValue)]
27+
internal sealed class NotNullAttribute : Attribute;
28+
29+
/// <summary>
30+
/// Specifies that when a method returns <see cref="ReturnValue" />, the parameter may be null even if the
31+
/// corresponding type disallows it.
32+
/// </summary>
33+
[AttributeUsage(AttributeTargets.Parameter)]
34+
internal sealed class MaybeNullWhenAttribute : Attribute {
35+
/// <summary>Initializes the attribute with the specified return value condition.</summary>
36+
/// <param name="returnValue">
37+
/// The return value condition. If the method returns this value, the associated parameter may be null.
38+
/// </param>
39+
public MaybeNullWhenAttribute(bool returnValue) {
40+
ReturnValue = returnValue;
41+
}
42+
43+
/// <summary> Gets the return value condition.</summary>
44+
public bool ReturnValue { get; }
45+
}
46+
47+
/// <summary>
48+
/// Specifies that when a method returns <see cref="ReturnValue" />, the parameter will not be null even if the
49+
/// corresponding type allows it.
50+
/// </summary>
51+
[AttributeUsage(AttributeTargets.Parameter)]
52+
internal sealed class NotNullWhenAttribute : Attribute {
53+
/// <summary>Initializes the attribute with the specified return value condition.</summary>
54+
/// <param name="returnValue">
55+
/// The return value condition. If the method returns this value, the associated parameter will not be null.
56+
/// </param>
57+
public NotNullWhenAttribute(bool returnValue) {
58+
ReturnValue = returnValue;
59+
}
60+
61+
/// <summary>Gets the return value condition.</summary>
62+
public bool ReturnValue { get; }
63+
}
64+
65+
/// <summary>Specifies that the output will be non-null if the named parameter is non-null.</summary>
66+
[AttributeUsage(AttributeTargets.Parameter | AttributeTargets.Property | AttributeTargets.ReturnValue, AllowMultiple = true)]
67+
internal sealed class NotNullIfNotNullAttribute : Attribute {
68+
/// <summary>Initializes the attribute with the associated parameter name.</summary>
69+
/// <param name="parameterName">
70+
/// The associated parameter name. The output will be non-null if the argument to the parameter specified is non-null.
71+
/// </param>
72+
public NotNullIfNotNullAttribute(string parameterName) {
73+
ParameterName = parameterName;
74+
}
75+
76+
/// <summary>Gets the associated parameter name.</summary>
77+
public string ParameterName { get; }
78+
}
79+
80+
/// <summary>Applied to a method that will never return under any circumstance.</summary>
81+
[AttributeUsage(AttributeTargets.Method, Inherited = false)]
82+
internal sealed class DoesNotReturnAttribute : Attribute;
83+
84+
/// <summary>Specifies that the method will not return if the associated Boolean parameter is passed the specified value.</summary>
85+
[AttributeUsage(AttributeTargets.Parameter)]
86+
internal sealed class DoesNotReturnIfAttribute : Attribute {
87+
/// <summary>Initializes the attribute with the specified parameter value.</summary>
88+
/// <param name="parameterValue">
89+
/// The condition parameter value. Code after the method will be considered unreachable by diagnostics if the argument
90+
/// to
91+
/// the associated parameter matches this value.
92+
/// </param>
93+
public DoesNotReturnIfAttribute(bool parameterValue) {
94+
ParameterValue = parameterValue;
95+
}
96+
97+
/// <summary>Gets the condition parameter value.</summary>
98+
public bool ParameterValue { get; }
99+
}
100+
101+
#endif
102+
103+
#if !NETCOREAPP
104+
105+
/// <summary>
106+
/// Specifies that the method or property will ensure that the listed field and property members have not-null
107+
/// values.
108+
/// </summary>
109+
[AttributeUsage(AttributeTargets.Method | AttributeTargets.Property, Inherited = false, AllowMultiple = true)]
110+
internal sealed class MemberNotNullAttribute : Attribute {
111+
/// <summary>Initializes the attribute with a field or property member.</summary>
112+
/// <param name="member">
113+
/// The field or property member that is promised to be not-null.
114+
/// </param>
115+
public MemberNotNullAttribute(string member) {
116+
Members = [member];
117+
}
118+
119+
/// <summary>Initializes the attribute with the list of field and property members.</summary>
120+
/// <param name="members">
121+
/// The list of field and property members that are promised to be not-null.
122+
/// </param>
123+
public MemberNotNullAttribute(params string[] members) {
124+
Members = members;
125+
}
126+
127+
/// <summary>Gets field or property member names.</summary>
128+
public string[] Members { get; }
129+
}
130+
131+
/// <summary>
132+
/// Specifies that the method or property will ensure that the listed field and property members have not-null
133+
/// values when returning with the specified return value condition.
134+
/// </summary>
135+
[AttributeUsage(AttributeTargets.Method | AttributeTargets.Property, Inherited = false, AllowMultiple = true)]
136+
internal sealed class MemberNotNullWhenAttribute : Attribute {
137+
/// <summary>Initializes the attribute with the specified return value condition and a field or property member.</summary>
138+
/// <param name="returnValue">
139+
/// The return value condition. If the method returns this value, the associated parameter will not be null.
140+
/// </param>
141+
/// <param name="member">
142+
/// The field or property member that is promised to be not-null.
143+
/// </param>
144+
public MemberNotNullWhenAttribute(bool returnValue, string member) {
145+
ReturnValue = returnValue;
146+
Members = [member];
147+
}
148+
149+
/// <summary>Initializes the attribute with the specified return value condition and list of field and property members.</summary>
150+
/// <param name="returnValue">
151+
/// The return value condition. If the method returns this value, the associated parameter will not be null.
152+
/// </param>
153+
/// <param name="members">
154+
/// The list of field and property members that are promised to be not-null.
155+
/// </param>
156+
public MemberNotNullWhenAttribute(bool returnValue, params string[] members) {
157+
ReturnValue = returnValue;
158+
Members = members;
159+
}
160+
161+
/// <summary>Gets the return value condition.</summary>
162+
public bool ReturnValue { get; }
163+
164+
/// <summary>Gets field or property member names.</summary>
165+
public string[] Members { get; }
166+
}
167+
168+
#endif

0 commit comments

Comments
 (0)