Skip to content
This repository was archived by the owner on Feb 14, 2022. It is now read-only.

Commit ddd2e81

Browse files
authored
Merge pull request #80 from JacopoWolf/rel/3.0
Release 3.0
2 parents 9db5c7b + fe6b01c commit ddd2e81

74 files changed

Lines changed: 1085 additions & 1770 deletions

File tree

Some content is hidden

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

README.md

Lines changed: 31 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,39 @@
1-
![dotNetStandard2.1](https://img.shields.io/badge/-Standard_2.1-5C2D91?logo=.net&style=flat-square)
2-
![csharp8.0](https://img.shields.io/badge/-8.0-239120?logo=c-sharp&style=flat-square)
31
![GitHub](https://img.shields.io/github/license/jacopowolf/stackinjector?style=flat-square)
2+
![GitHub contributors](https://img.shields.io/github/contributors-anon/jacopowolf/stackinjector?color=informational&style=flat-square)
43
![Maintenance](https://img.shields.io/maintenance/yes/2020?style=flat-square)
54
![GitHub open bug issues](https://img.shields.io/github/issues/jacopowolf/stackinjector/bug?style=flat-square)
65
[![Nuget](https://img.shields.io/nuget/vpre/StackInjector?logo=nuget&style=flat-square)](https://www.nuget.org/packages/StackInjector)
76
[![Nuget](https://img.shields.io/nuget/dt/StackInjector?logo=nuget&style=flat-square)](https://www.nuget.org/packages/StackInjector)
87

98

9+
1010
<br/>
1111
<p align="center">
12-
1312
<img src="logo/StackInjector_logo.svg" height="128" />
13+
</p>
14+
1415
<h1 align="center">Stack Injector</h1>
1516

1617
<p align="center">
17-
Simple, fast and easy-to-use dependency injection
18-
<br/>
18+
<img src="https://img.shields.io/badge/-Standard_2.1-5C2D91?logo=.net&style=for-the-badge"/>
19+
<img src="https://img.shields.io/badge/-8.0-239120?logo=c-sharp&style=for-the-badge"/>
20+
<img src="https://img.shields.io/badge/made%20with-%E2%99%A5-FF69B4?style=for-the-badge"/>
21+
<br><br>
22+
Simple, Easy-to-use and Fast dependency injection<br>
1923
<strong><a href="https://github.com/JacopoWolf/StackInjector/wiki">Documentation »<a></strong>
20-
<br>
21-
<br>
24+
<br><br>
2225
<a href="https://www.nuget.org/packages/StackInjector">Download</a>
2326
·
2427
<a href="https://github.com/JacopoWolf/StackInjector/issues/new/choose">Report Bug</a>
2528
·
2629
<a href="https://github.com/JacopoWolf/StackInjector/issues/new/choose">Request Feature</a>
2730
</p>
2831

29-
</p>
3032

3133

3234
---
3335

36+
Table of Contents
3437
- [About](#about)
3538
- [Installation](#installation)
3639
- [Usage](#usage)
@@ -43,7 +46,9 @@ Simple, fast and easy-to-use dependency injection
4346

4447
There are a lot of dependency injection frameworks for .NET, but every single one of them has some complicated specifics you have to learn (like active registration of components) and sometimes you don't really have full control of what to inject into your instances.
4548

46-
If you want to use an extremely easy dependency injection framework, then *StackInjector* is made for you!
49+
If you want to use an extremely easy dependency injection framework, and also use the latest features the C# language has to offer, then *StackInjector* is made for you!
50+
51+
*Also ships with some nice settings presets to suit your coding style!*
4752

4853

4954
## Installation
@@ -58,11 +63,11 @@ Or visit the [Nuget page](https://www.nuget.org/packages/StackInjector) for more
5863

5964
## Usage
6065

61-
In-depth tutorials and explanations can be found in the [wiki tutorials section](https://github.com/JacopoWolf/StackInjector/wiki/Tutorial_Introduction)
66+
In-depth tutorials and explanations can be found in the repository's [Wiki](https://github.com/JacopoWolf/StackInjector/wiki)
6267

6368
---
6469

65-
Plan your components as **interfaces** and *implement* them!
70+
You can plan your components as **interfaces** and *implement* them!
6671

6772
As clean as you can get!
6873

@@ -80,13 +85,12 @@ using StackInjector.Attributes;
8085
[Service(Version=1.0)]
8186
class SimpleFooFilter : IFooFilter
8287
{
83-
// both fields and properties, to explicitly annotate with [Served]
84-
// if you want them injected
88+
// by default settings, you have to explicitly annotate with [Served]
89+
// the properties or fields you want injected
8590
8691
[Served]
87-
IDatabaseAccess database { get; set; }
92+
IDatabaseAccess Database { get; set; }
8893

89-
// works with properties too!
9094
[Served]
9195
IFooFilter filter;
9296

@@ -101,52 +105,36 @@ class SimpleFooFilter : IFooFilter
101105
}
102106
```
103107

104-
Everything **must** have an attribute, allowing for **extremely readable code** and for **granular control** over the injection process.
108+
Everything **must** be explicit (`[Service]`,`[Served]` and `[Ignored]` attributes) allowing for **extremely readable code** and for **granular control** over the injection process.
105109

106110
---
107111

108-
You then have multiple options on how you want to initialize your application!
112+
You then have multiple options on how to initialize your application, and every single one of them type-safe!
109113

114+
**synchronous**
115+
116+
use a delegate
110117
```cs
111-
using StackInjector;
118+
Injector.From<IMyAppEntryPoint>().Start( app => app.Work() );
112119
```
113-
114-
**synchronous**
120+
or just get the instance of the entry point
115121
```cs
116-
Injector.From<IMyAppEntryPoint>().Start();
122+
Injector.From<IMyAppEntryPoint>().Entry.Work();
117123
```
118124

119125
**asynchronous**
120126
```cs
121-
// using allows for safe disposing of the resources when no more needed
122-
using var app = Injector.AsyncFrom<MyAsyncAppEntryPoint>();
127+
// the using keyword allows for safe disposing of the resources
128+
using var app = Injector.AsyncFrom<IMyAsyncAppEntryPoint>( (e,i,t) => e.Elaborate(i,t) );
123129

124130
// can be called from anywhere and guarantee consistency
125131
app.Submit( someInput );
126132

127-
// waiting for completed tasks is as simple as an await foreach loop
128-
await foreach ( var result in app.Elaborated<string>() )
133+
// waiting for completed tasks is this simple
134+
await foreach ( var result in app.Elaborated() )
129135
Console.WriteLine( result );
130136
```
131137

132-
**generics**
133-
134-
For users who do care about type safety, there are also generic options! Both synchronous and asynchronous.
135-
136-
```cs
137-
// generic asynchronous wrapper
138-
using var app =
139-
Injector.AsyncFrom<MyAsyncAppEntryPoint,string,int>
140-
(
141-
async (entryPoint,element,cancellationToken)
142-
=> await entryPoint.MyCustomLogic(element)
143-
);
144-
```
145-
146-
---
147-
148-
For **more** information and in-depth **tutorials**, look at the simple tutorials in the [wiki](https://github.com/JacopoWolf/StackInjector/wiki)
149-
150138

151139

152140
## Contributing

SECURITY.md

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,19 +3,23 @@
33
## Supported Versions
44

55

6-
| Version | Supported |
7-
| ------- | ------------------ |
8-
| 2.x | :white_check_mark: |
9-
| 1.x | :o2: |
6+
| Version | Supported | Notes |
7+
| ------: | :----------------- | --------------------------- |
8+
| 3.x | :white_check_mark: | |
9+
| 2.3 | :o2: | *tutorials still available* |
10+
| 1.1 | :o2: | |
1011

1112

12-
:white_check_mark: LTS version
13+
---
1314

14-
:ballot_box_with_check: supported
1515

16-
:o2: not supported
16+
:white_check_mark: supported
1717

18-
:no_entry: not supported with critical bugs
18+
:ballot_box_with_check: supported, end of life
19+
20+
:o2: NOT supported
21+
22+
:no_entry: NOT supported, critical bugs
1923

2024
## Reporting a Vulnerability
2125

StackInjector.sln

Lines changed: 10 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,9 @@ VisualStudioVersion = 16.0.30011.22
55
MinimumVisualStudioVersion = 10.0.40219.1
66
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "StackInjector", "StackInjector\StackInjector.csproj", "{FF8663EB-B6F5-41B1-A99E-758E446D5E39}"
77
EndProject
8-
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "StackInjector.TEST.SimpleStack", "tests\StackInjector.TEST.SimpleStack\StackInjector.TEST.SimpleStack.csproj", "{C9E08D89-7800-425A-8E73-EDEF57E492D4}"
9-
ProjectSection(ProjectDependencies) = postProject
10-
{FF8663EB-B6F5-41B1-A99E-758E446D5E39} = {FF8663EB-B6F5-41B1-A99E-758E446D5E39}
11-
EndProjectSection
8+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "StackInjector.TEST.BlackBox", "tests\StackInjector.TEST.BlackBox\StackInjector.TEST.BlackBox.csproj", "{6AE7F918-D84F-4AEC-A49F-A232DB8F442F}"
129
EndProject
13-
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "StackInjector.TEST.Versioning", "tests\StackInjector.TEST.Versioning\StackInjector.TEST.Versioning.csproj", "{A095AA2C-B958-431F-B9CA-31CC81E5623B}"
14-
EndProject
15-
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "StackInjector.TEST.Async", "tests\StackInjector.TEST.Async\StackInjector.TEST.Async.csproj", "{71E7BE96-4B1A-4C40-BAC2-7D91409AED4C}"
16-
EndProject
17-
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "StackInjector.TEST.ComplexStack", "tests\StackInjector.TEST.ComplexStack\StackInjector.TEST.ComplexStack.csproj", "{C722EBFC-06FF-411A-B813-9915E3E6FA53}"
10+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "StackInjector.TEST.ExternalAssembly", "tests\StackInjector.TEST.ExternalAssembly\StackInjector.TEST.ExternalAssembly.csproj", "{BCCEE1DD-59FB-4A11-8D48-6213C2D750CA}"
1811
EndProject
1912
Global
2013
GlobalSection(SolutionConfigurationPlatforms) = preSolution
@@ -26,22 +19,14 @@ Global
2619
{FF8663EB-B6F5-41B1-A99E-758E446D5E39}.Debug|Any CPU.Build.0 = Debug|Any CPU
2720
{FF8663EB-B6F5-41B1-A99E-758E446D5E39}.Release|Any CPU.ActiveCfg = Release|Any CPU
2821
{FF8663EB-B6F5-41B1-A99E-758E446D5E39}.Release|Any CPU.Build.0 = Release|Any CPU
29-
{C9E08D89-7800-425A-8E73-EDEF57E492D4}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
30-
{C9E08D89-7800-425A-8E73-EDEF57E492D4}.Debug|Any CPU.Build.0 = Debug|Any CPU
31-
{C9E08D89-7800-425A-8E73-EDEF57E492D4}.Release|Any CPU.ActiveCfg = Release|Any CPU
32-
{C9E08D89-7800-425A-8E73-EDEF57E492D4}.Release|Any CPU.Build.0 = Release|Any CPU
33-
{A095AA2C-B958-431F-B9CA-31CC81E5623B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
34-
{A095AA2C-B958-431F-B9CA-31CC81E5623B}.Debug|Any CPU.Build.0 = Debug|Any CPU
35-
{A095AA2C-B958-431F-B9CA-31CC81E5623B}.Release|Any CPU.ActiveCfg = Release|Any CPU
36-
{A095AA2C-B958-431F-B9CA-31CC81E5623B}.Release|Any CPU.Build.0 = Release|Any CPU
37-
{71E7BE96-4B1A-4C40-BAC2-7D91409AED4C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
38-
{71E7BE96-4B1A-4C40-BAC2-7D91409AED4C}.Debug|Any CPU.Build.0 = Debug|Any CPU
39-
{71E7BE96-4B1A-4C40-BAC2-7D91409AED4C}.Release|Any CPU.ActiveCfg = Release|Any CPU
40-
{71E7BE96-4B1A-4C40-BAC2-7D91409AED4C}.Release|Any CPU.Build.0 = Release|Any CPU
41-
{C722EBFC-06FF-411A-B813-9915E3E6FA53}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
42-
{C722EBFC-06FF-411A-B813-9915E3E6FA53}.Debug|Any CPU.Build.0 = Debug|Any CPU
43-
{C722EBFC-06FF-411A-B813-9915E3E6FA53}.Release|Any CPU.ActiveCfg = Release|Any CPU
44-
{C722EBFC-06FF-411A-B813-9915E3E6FA53}.Release|Any CPU.Build.0 = Release|Any CPU
22+
{6AE7F918-D84F-4AEC-A49F-A232DB8F442F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
23+
{6AE7F918-D84F-4AEC-A49F-A232DB8F442F}.Debug|Any CPU.Build.0 = Debug|Any CPU
24+
{6AE7F918-D84F-4AEC-A49F-A232DB8F442F}.Release|Any CPU.ActiveCfg = Release|Any CPU
25+
{6AE7F918-D84F-4AEC-A49F-A232DB8F442F}.Release|Any CPU.Build.0 = Release|Any CPU
26+
{BCCEE1DD-59FB-4A11-8D48-6213C2D750CA}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
27+
{BCCEE1DD-59FB-4A11-8D48-6213C2D750CA}.Debug|Any CPU.Build.0 = Debug|Any CPU
28+
{BCCEE1DD-59FB-4A11-8D48-6213C2D750CA}.Release|Any CPU.ActiveCfg = Release|Any CPU
29+
{BCCEE1DD-59FB-4A11-8D48-6213C2D750CA}.Release|Any CPU.Build.0 = Release|Any CPU
4530
EndGlobalSection
4631
GlobalSection(SolutionProperties) = preSolution
4732
HideSolutionNode = FALSE
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
using System;
2+
3+
namespace StackInjector.Attributes
4+
{
5+
6+
/// <summary>
7+
/// Indicates this field or property should be ignored from injection
8+
/// </summary>
9+
[AttributeUsage(AttributeTargets.Property | AttributeTargets.Field, AllowMultiple = false, Inherited = true)]
10+
public sealed class IgnoredAttribute : Attribute
11+
{
12+
13+
}
14+
15+
}

StackInjector/Attributes/ServedAttribute.cs

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,19 @@ public sealed class ServedAttribute : Attribute
1919
/// <para>How the specified TargetVersion should be found.</para>
2020
/// <para>could be overriden by <see cref="StackWrapperSettings"/></para>
2121
/// </summary>
22-
public ServedVersionTargetingMethod? TargetingMethod { get; set; } = null;
22+
public ServedVersionTargetingMethod TargetingMethod
23+
{
24+
get => this._targeting;
25+
set
26+
{
27+
this._targetingDefined = true;
28+
this._targeting = value;
29+
}
30+
}
31+
32+
33+
private ServedVersionTargetingMethod _targeting;
34+
internal bool _targetingDefined = false;
2335

2436
}
2537

StackInjector/Attributes/ServiceAttribute.cs

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,20 +4,37 @@
44
namespace StackInjector.Attributes
55
{
66
/// <summary>
7-
/// Indicates this class can be used as a Service
7+
/// Allows a class to be used a service for other classes.
88
/// </summary>
99
[AttributeUsage(AttributeTargets.Class, Inherited = true, AllowMultiple = false)]
1010
public sealed class ServiceAttribute : Attribute
1111
{
1212
/// <summary>
13-
/// The version of this service implementation
13+
/// The version of this service.
1414
/// </summary>
1515
public double Version { get; set; } = -0.0;
1616

1717
/// <summary>
18-
/// How properties and fields of this service should be served
18+
/// The instantiation pattern for this service.
1919
/// </summary>
20-
public ServingMethods Serving { get; set; } = Injector.Defaults.ServingMethod;
20+
public InstantiationPattern Pattern { get; set; } = InstantiationPattern.Singleton;
21+
22+
23+
/// <summary>
24+
/// How properties and fields of this service should be injected.
25+
/// </summary>
26+
public ServingMethods Serving
27+
{
28+
get => this._serving;
29+
set
30+
{
31+
this._servingDefined = true;
32+
this._serving = value;
33+
}
34+
}
35+
36+
private ServingMethods _serving;
37+
internal bool _servingDefined = false;
2138
}
2239

2340
}

StackInjector/Behaviours/SingleInstanceHolder.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@ public void AddInstance ( Type type, object instance )
1919
=> this.objects[type] = instance;
2020

2121
public void RemoveInstance ( Type type, object instance )
22-
{
23-
this.objects[type] = null;
22+
{
23+
this.objects[type] = null;
2424
this.injected.Remove(instance);
2525
}
2626

StackInjector/Core/AsyncStackWrapperCore.logic.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ Task listAwaiter ()
6161
=> this.emptyListAwaiter.WaitAsync();
6262

6363

64-
switch( this.Settings.asyncWaitingMethod )
64+
switch( this.Settings._asyncWaitingMethod )
6565
{
6666

6767
case AsyncWaitingMethod.Exit:
@@ -79,7 +79,7 @@ Task listAwaiter ()
7979

8080
case AsyncWaitingMethod.Timeout:
8181
var list = listAwaiter();
82-
var timeout = Task.Delay( this.Settings.asyncWaitTime );
82+
var timeout = Task.Delay( this.Settings._asyncWaitTime );
8383

8484
// if the timeout elapses first, then stop waiting
8585
return (await Task.WhenAny(list, timeout).ConfigureAwait(true)) == timeout;

StackInjector/Core/Cloning/ClonedCore.cs

Lines changed: 3 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
using StackInjector.Wrappers;
2-
using StackInjector.Wrappers.Generic;
32

43
namespace StackInjector.Core.Cloning
54
{
@@ -13,44 +12,24 @@ internal ClonedCore ( InjectionCore clonedCore )
1312
this.clonedCore = clonedCore;
1413

1514

16-
public IAsyncStackWrapper ToAsyncWrapper<T> () where T : IAsyncStackEntryPoint
17-
{
18-
var wrapper = new AsyncStackWrapper( this.clonedCore );
19-
20-
this.clonedCore.entryPoint = typeof(T);
21-
this.clonedCore.ServeAll();
22-
23-
return wrapper;
24-
}
25-
2615
public IAsyncStackWrapper<TEntry, TIn, TOut> ToAsyncWrapper<TEntry, TIn, TOut> ( AsyncStackDigest<TEntry, TIn, TOut> digest )
2716
{
2817
var wrapper = new AsyncStackWrapper<TEntry,TIn,TOut>( this.clonedCore )
2918
{
3019
StackDigest = digest
3120
};
3221

33-
this.clonedCore.entryPoint = typeof(TEntry);
22+
this.clonedCore.EntryPoint = typeof(TEntry);
3423
this.clonedCore.ServeAll();
3524

3625
return wrapper;
3726
}
3827

39-
public IStackWrapper<T> ToGenericWrapper<T> ()
28+
public IStackWrapper<T> ToWrapper<T> ()
4029
{
4130
var wrapper = new StackWrapper<T>(this.clonedCore);
4231

43-
this.clonedCore.entryPoint = typeof(T);
44-
this.clonedCore.ServeAll();
45-
46-
return wrapper;
47-
}
48-
49-
public IStackWrapper ToWrapper<T> () where T : IStackEntryPoint
50-
{
51-
var wrapper = new StackWrapper( this.clonedCore );
52-
53-
this.clonedCore.entryPoint = typeof(T);
32+
this.clonedCore.EntryPoint = typeof(T);
5433
this.clonedCore.ServeAll();
5534

5635
return wrapper;

0 commit comments

Comments
 (0)