-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
1ede20d
commit f7439ed
Showing
21 changed files
with
313 additions
and
55 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
<component name="ProjectRunConfigurationManager"> | ||
<configuration default="false" name="Build and pack libraries" type="DotNetProject" factoryName=".NET Project"> | ||
<option name="EXE_PATH" value="$PROJECT_DIR$/build/bin/Debug/net8.0/build.exe" /> | ||
<option name="PROGRAM_PARAMETERS" value="libs" /> | ||
<option name="WORKING_DIRECTORY" value="$PROJECT_DIR$" /> | ||
<option name="PASS_PARENT_ENVS" value="1" /> | ||
<option name="USE_EXTERNAL_CONSOLE" value="0" /> | ||
<option name="USE_MONO" value="0" /> | ||
<option name="RUNTIME_ARGUMENTS" value="" /> | ||
<option name="PROJECT_PATH" value="$PROJECT_DIR$/build/build.csproj" /> | ||
<option name="PROJECT_EXE_PATH_TRACKING" value="1" /> | ||
<option name="PROJECT_ARGUMENTS_TRACKING" value="1" /> | ||
<option name="PROJECT_WORKING_DIRECTORY_TRACKING" value="0" /> | ||
<option name="PROJECT_KIND" value="DotNetCore" /> | ||
<option name="PROJECT_TFM" value="net8.0" /> | ||
<method v="2"> | ||
<option name="Build" /> | ||
</method> | ||
</configuration> | ||
</component> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
<component name="ProjectRunConfigurationManager"> | ||
<configuration default="false" name="Compatibility checks" type="DotNetProject" factoryName=".NET Project"> | ||
<option name="EXE_PATH" value="$PROJECT_DIR$/build/bin/Debug/net8.0/build.exe" /> | ||
<option name="PROGRAM_PARAMETERS" value="check" /> | ||
<option name="WORKING_DIRECTORY" value="$PROJECT_DIR$" /> | ||
<option name="PASS_PARENT_ENVS" value="1" /> | ||
<option name="USE_EXTERNAL_CONSOLE" value="0" /> | ||
<option name="USE_MONO" value="0" /> | ||
<option name="RUNTIME_ARGUMENTS" value="" /> | ||
<option name="PROJECT_PATH" value="$PROJECT_DIR$/build/build.csproj" /> | ||
<option name="PROJECT_EXE_PATH_TRACKING" value="1" /> | ||
<option name="PROJECT_ARGUMENTS_TRACKING" value="1" /> | ||
<option name="PROJECT_WORKING_DIRECTORY_TRACKING" value="0" /> | ||
<option name="PROJECT_KIND" value="DotNetCore" /> | ||
<option name="PROJECT_TFM" value="net8.0" /> | ||
<method v="2"> | ||
<option name="Build" /> | ||
</method> | ||
</configuration> | ||
</component> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
#### Inject attribute | ||
|
||
[![CSharp](https://img.shields.io/badge/C%23-code-blue.svg)](../tests/Pure.DI.UsageTests/Attributes/InjectAttributeScenario.cs) | ||
|
||
If you want to use attributes in your libraries but don't want to create your own, you can add this package to your projects: | ||
|
||
[![NuGet](https://buildstats.info/nuget/Pure.DI.Abstractions)](https://www.nuget.org/packages/Pure.DI.Abstractions) | ||
|
||
It contains attributes like `Inject` and `Inject<T>` that work for constructors and their arguments, methods and their arguments, properties and fields. They allow you to setup all injection parameters. | ||
|
||
|
||
```c# | ||
using Pure.DI.Abstractions; | ||
|
||
interface IPerson; | ||
|
||
class Person([Inject("NikName")] string name) : IPerson | ||
{ | ||
private object? _state; | ||
|
||
[Inject<int>] | ||
internal object Id = ""; | ||
|
||
public void Initialize([Inject<Uri>("Person Uri", 1)] object state) => | ||
_state = state; | ||
|
||
public override string ToString() => $"{Id} {name} {_state}"; | ||
} | ||
|
||
DI.Setup(nameof(PersonComposition)) | ||
.Arg<int>("personId") | ||
.Bind("Person Uri").To(_ => new Uri("https://github.com/DevTeam/Pure.DI")) | ||
.Bind("NikName").To(_ => "Nik") | ||
.Bind().To<Person>() | ||
|
||
// Composition root | ||
.Root<IPerson>("Person"); | ||
|
||
var composition = new PersonComposition(personId: 123); | ||
var person = composition.Person; | ||
person.ToString().ShouldBe("123 Nik https://github.com/DevTeam/Pure.DI"); | ||
``` | ||
|
||
This package should also be included in a project: | ||
|
||
[![NuGet](https://buildstats.info/nuget/Pure.DI)](https://www.nuget.org/packages/Pure.DI) | ||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
// ReSharper disable ClassNeverInstantiated.Global | ||
// ReSharper disable RedundantNameQualifier | ||
// ReSharper disable InvalidXmlDocComment | ||
#pragma warning disable CS9113 // Parameter is unread. | ||
namespace Pure.DI.Abstractions; | ||
|
||
/// <summary> | ||
/// A universal DI attribute that allows to specify the tag and ordinal of an injection. | ||
/// </summary> | ||
/// <param name="tag">The injection tag. See also <see cref="IBinding.Tags"/></param>. | ||
/// <param name="ordinal">The injection ordinal.</param> | ||
[global::System.AttributeUsage(global::System.AttributeTargets.Constructor | global::System.AttributeTargets.Method | global::System.AttributeTargets.Parameter | global::System.AttributeTargets.Property | global::System.AttributeTargets.Field)] | ||
public sealed class InjectAttribute(object? tag = default, int ordinal = default) : global::System.Attribute; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
// ReSharper disable ClassNeverInstantiated.Global | ||
// ReSharper disable UnusedTypeParameter | ||
// ReSharper disable RedundantNameQualifier | ||
// ReSharper disable InvalidXmlDocComment | ||
#pragma warning disable CS9113 // Parameter is unread. | ||
namespace Pure.DI.Abstractions; | ||
|
||
/// <summary> | ||
/// A universal DI attribute that allows to specify the type, tag, and ordinal of an injection. | ||
/// </summary> | ||
/// <param name="tag">The injection tag. See also <see cref="IBinding.Tags"/></param>. | ||
/// <param name="ordinal">The injection ordinal.</param> | ||
/// <typeparam name="T">The injection type. See also <see cref="IConfiguration.Bind{T}"/> and <see cref="IBinding.Bind{T}"/></typeparam> | ||
[global::System.AttributeUsage(global::System.AttributeTargets.Constructor | global::System.AttributeTargets.Method | global::System.AttributeTargets.Parameter | global::System.AttributeTargets.Property | global::System.AttributeTargets.Field)] | ||
public sealed class InjectAttribute<T>(object? tag = default, int ordinal = default) : global::System.Attribute; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<TargetFrameworks>net20;net35;net40;net45;net48;netstandard1.0;netstandard1.1;netstandard1.2;netstandard1.3;netstandard1.4;netstandard1.5;netstandard1.6;netstandard2.0;netstandard2.1;netcoreapp1.0;netcoreapp1.1;netcoreapp2.0;netcoreapp2.1;netcoreapp2.2;netcoreapp3.0;netcoreapp3.1;net5.0;net6.0;net7.0;net8.0</TargetFrameworks> | ||
<IsPackable>true</IsPackable> | ||
<ImplicitUsings>false</ImplicitUsings> | ||
<PackageId>$(BasePackageId).Abstractions</PackageId> | ||
<Description>Abstractions of $(BasePackageId). $(Description)</Description> | ||
<DefineConstants>$(DefineConstants);PUREDI_NET_ANY</DefineConstants> | ||
<NoWarn>NU1902;NU1903;NU3005</NoWarn> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<Compile Remove="any\Pure.DI\Abstractions\Composition.g.cs"/> | ||
<Content Include="any\Pure.DI\Abstractions\Composition.g.cs" buildAction="Compile" > | ||
<Pack>true</Pack> | ||
<PackagePath>contentFiles/cs/any/Pure.DI/Abstractions</PackagePath> | ||
</Content> | ||
<PackageReference Include="Microsoft.NETFramework.ReferenceAssemblies.net20" Version="1.0.3" Condition="'$(TargetFramework)' == 'net20' "> | ||
<PrivateAssets>all</PrivateAssets> | ||
<IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets> | ||
</PackageReference> | ||
<PackageReference Include="Microsoft.NETFramework.ReferenceAssemblies.net35" Version="1.0.3" Condition="'$(TargetFramework)' == 'net35' "> | ||
<PrivateAssets>all</PrivateAssets> | ||
<IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets> | ||
</PackageReference> | ||
<PackageReference Include="Microsoft.NETFramework.ReferenceAssemblies.net40" Version="1.0.3" Condition="'$(TargetFramework)' == 'net40' "> | ||
<PrivateAssets>all</PrivateAssets> | ||
<IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets> | ||
</PackageReference> | ||
<PackageReference Include="Microsoft.NETFramework.ReferenceAssemblies.net45" Version="1.0.3" Condition="'$(TargetFramework)' == 'net45' "> | ||
<PrivateAssets>all</PrivateAssets> | ||
<IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets> | ||
</PackageReference> | ||
<PackageReference Include="Microsoft.NETFramework.ReferenceAssemblies.net48" Version="1.0.3" Condition="'$(TargetFramework)' == 'net48' "> | ||
<PrivateAssets>all</PrivateAssets> | ||
<IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets> | ||
</PackageReference> | ||
</ItemGroup> | ||
|
||
</Project> |
22 changes: 22 additions & 0 deletions
22
src/Pure.DI.Abstractions/any/Pure.DI/Abstractions/Composition.g.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
// <auto-generated/> | ||
// #pragma warning disable | ||
#if !PUREDI_API_SUPPRESSION || PUREDI_API_V1 | ||
#pragma warning disable | ||
namespace Pure.DI.Abstractions | ||
{ | ||
internal static class Composition | ||
{ | ||
[global::System.Diagnostics.Conditional("A2768DE22DE3E430C9653990D516CC9B")] | ||
private static void Setup() | ||
{ | ||
global::Pure.DI.DI.Setup(kind: global::Pure.DI.CompositionKind.Global) | ||
.TagAttribute<global::Pure.DI.Abstractions.InjectAttribute<TT>>() | ||
.OrdinalAttribute<global::Pure.DI.Abstractions.InjectAttribute<TT>>(1) | ||
.TypeAttribute<global::Pure.DI.Abstractions.InjectAttribute<TT>>() | ||
.TagAttribute<global::Pure.DI.Abstractions.InjectAttribute>() | ||
.OrdinalAttribute<global::Pure.DI.Abstractions.InjectAttribute>(1); | ||
} | ||
} | ||
} | ||
#pragma warning restore | ||
#endif |
Oops, something went wrong.