-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #13 from Moreault/2_2_0
2 2 0
- Loading branch information
Showing
20 changed files
with
256 additions
and
106 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
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,12 @@ | ||
namespace AutoInject.Sample; | ||
|
||
public abstract class AbstractGreeter | ||
{ | ||
public abstract string Greet(); | ||
} | ||
|
||
[AutoInject<AbstractGreeter>] | ||
public class ConcreteGreeter : AbstractGreeter, IWeirdGreeter | ||
{ | ||
public override string Greet() => "Hello, theoretically"; | ||
} |
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 |
---|---|---|
@@ -1,18 +1,19 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<OutputType>Exe</OutputType> | ||
<TargetFramework>net7.0</TargetFramework> | ||
<ImplicitUsings>enable</ImplicitUsings> | ||
<Nullable>enable</Nullable> | ||
</PropertyGroup> | ||
<PropertyGroup> | ||
<OutputType>Exe</OutputType> | ||
<TargetFramework>net7.0</TargetFramework> | ||
<ImplicitUsings>enable</ImplicitUsings> | ||
<Nullable>enable</Nullable> | ||
<IsPackable>false</IsPackable> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="ToolBX.AssemblyInitializer.Console" Version="2.0.2" /> | ||
</ItemGroup> | ||
<ItemGroup> | ||
<PackageReference Include="ToolBX.AssemblyInitializer.Console" Version="2.2.0-beta4" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<ProjectReference Include="..\AutoInject\AutoInject.csproj" /> | ||
</ItemGroup> | ||
<ItemGroup> | ||
<ProjectReference Include="..\AutoInject\AutoInject.csproj" /> | ||
</ItemGroup> | ||
|
||
</Project> |
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 |
---|---|---|
|
@@ -6,5 +6,7 @@ public enum GreetingKind | |
Familiar, | ||
Complex, | ||
Generic, | ||
OpenGeneric | ||
OpenGeneric, | ||
Weird, | ||
Abstract, | ||
} |
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,15 @@ | ||
namespace AutoInject.Sample; | ||
|
||
public interface IWeirdGreeter | ||
{ | ||
string Greet(); | ||
} | ||
|
||
//We need to provide the interface's type to AutoInject since it has a wildly different name from its interface and implements multiple | ||
[AutoInject<IWeirdGreeter>()] | ||
public class Greta : IWeirdGreeter, IFormalGreeter | ||
{ | ||
public string Greet() => "Siap!"; | ||
|
||
string IFormalGreeter.Greet() => Greet(); | ||
} |
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 |
---|---|---|
@@ -1,9 +1,35 @@ | ||
namespace ToolBX.AutoInject; | ||
|
||
[AttributeUsage(AttributeTargets.Class)] | ||
public class AutoInjectAttribute : Attribute | ||
public sealed class AutoInjectAttribute : AutoInjectAttributeBase | ||
{ | ||
public ServiceLifetime Lifetime { get; init; } | ||
|
||
[Obsolete("Use AutoInject<T> instead. Will be removed in 3.0.0")] | ||
public Type? Interface { get; init; } | ||
|
||
public AutoInjectAttribute() { } | ||
public AutoInjectAttribute(ServiceLifetime lifetime) : base(lifetime) { } | ||
} | ||
|
||
// ReSharper disable once UnusedTypeParameter : It is used via reflection and implementing types outside its assembly | ||
public sealed class AutoInjectAttribute<T> : AutoInjectAttributeBase | ||
{ | ||
public AutoInjectAttribute() { } | ||
public AutoInjectAttribute(ServiceLifetime lifetime) : base(lifetime) { } | ||
} | ||
|
||
public abstract class AutoInjectAttributeBase : Attribute | ||
{ | ||
public ServiceLifetime Lifetime | ||
{ | ||
get => RealLifetime ?? (ServiceLifetime)(-1); | ||
init => RealLifetime = value; | ||
} | ||
internal ServiceLifetime? RealLifetime; | ||
|
||
internal AutoInjectAttributeBase() { } | ||
|
||
internal AutoInjectAttributeBase(ServiceLifetime lifetime) | ||
{ | ||
Lifetime = lifetime; | ||
} | ||
} |
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,6 @@ | ||
namespace ToolBX.AutoInject; | ||
|
||
public sealed record AutoInjectOptions | ||
{ | ||
public ServiceLifetime DefaultLifetime { get; init; } = ServiceLifetime.Singleton; | ||
} |
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 |
---|---|---|
@@ -1,6 +1,9 @@ | ||
global using Microsoft.Extensions.Configuration; | ||
// Global using directives | ||
|
||
global using Microsoft.Extensions.Configuration; | ||
global using Microsoft.Extensions.DependencyInjection; | ||
global using System.Reflection; | ||
global using System.Text.RegularExpressions; | ||
global using ToolBX.AutoInject.Resources; | ||
global using ToolBX.Reflection4Humans.Extensions; | ||
global using ToolBX.Reflection4Humans.TypeFetcher; |
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
Oops, something went wrong.