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

Commit df44d35

Browse files
authored
Merge pull request #174 from JacopoWolf/rel/4
Release 4.0.0-alpha.1
2 parents 47ee6a5 + dcfdc29 commit df44d35

46 files changed

Lines changed: 1294 additions & 1326 deletions

Some content is hidden

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

.github/workflows/dotnet_pullr.yml

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
name: .NET PR tests
2+
3+
# runs only on pull requests
4+
on:
5+
pull_request:
6+
branches:
7+
- 'master'
8+
- 'rel/**'
9+
- 'dev/**'
10+
paths-ignore:
11+
- '**.md'
12+
- '**.txt'
13+
- '**.png'
14+
15+
16+
jobs:
17+
18+
prtest:
19+
runs-on: ${{ matrix.os }}
20+
env:
21+
DOTNET_NOLOGO: true
22+
strategy:
23+
fail-fast: false
24+
matrix:
25+
os: ['ubuntu-latest','windows-latest']
26+
27+
steps:
28+
- uses: actions/checkout@v2
29+
30+
- name: Setup .NET
31+
uses: actions/setup-dotnet@v1
32+
with:
33+
dotnet-version: '5.0.x'
34+
35+
- name: Clean cache
36+
run: dotnet clean --configuration Release && dotnet nuget locals all --clear
37+
38+
- name: Install dependencies
39+
run: dotnet restore
40+
41+
- name: Build
42+
run: dotnet build --no-restore --configuration Release
43+
44+
- name: Test
45+
run: dotnet test --no-restore --configuration Release --logger "console;verbosity=detailed"
46+
Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,19 @@
11
name: .NET tests
22

3+
# runs on every push on every branch
34
on:
45
push:
56
paths-ignore:
67
- '**.md'
78
- '**.txt'
8-
pull_request:
9-
branches:
10-
- 'master'
11-
- 'rel/**'
12-
- 'dev/**'
139

14-
10+
1511
jobs:
1612

1713
test:
18-
runs-on: ${{ matrix.os }}
14+
runs-on: 'ubuntu-latest'
1915
env:
2016
DOTNET_NOLOGO: true
21-
strategy:
22-
fail-fast: false
23-
matrix:
24-
os: ['ubuntu-latest','windows-latest']
2517

2618
steps:
2719
- uses: actions/checkout@v2

.github/workflows/nuget.yml

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ on:
88
jobs:
99

1010
test:
11+
1112
runs-on: ${{ matrix.os }}
1213
env:
1314
DOTNET_NOLOGO: true
@@ -24,18 +25,22 @@ jobs:
2425
with:
2526
dotnet-version: '5.0.x'
2627

28+
- name: Clean cache
29+
run: dotnet clean --configuration Release && dotnet nuget locals all --clear
30+
2731
- name: Install dependencies
2832
run: dotnet restore
2933

3034
- name: Build
3135
run: dotnet build --no-restore --configuration Release
3236

3337
- name: Test
34-
run: dotnet test --no-restore --configuration Release --logger "console;verbosity=detailed"
38+
run: dotnet test --no-restore --configuration Release --logger "console;verbosity=detailed"
3539

3640

3741

3842
release:
43+
3944
needs: [test]
4045
runs-on: ubuntu-latest
4146

@@ -47,12 +52,15 @@ jobs:
4752
with:
4853
dotnet-version: '5.0.x'
4954

55+
- name: Install dependencies
56+
run: dotnet restore StackInjector/StackInjector.csproj
57+
5058
#run: echo ::set-env name=RELEASE_VERSION::${GITHUB_REF:10}
5159
- name: Version
5260
run: echo "RELEASE_VERSION=${GITHUB_REF#refs/*/}" >> $GITHUB_ENV
5361

5462
- name: Pack
55-
run: dotnet pack StackInjector --configuration Release -p:PackageVersion=$RELEASE_VERSION
63+
run: dotnet pack StackInjector --no-restore --configuration Release -p:PackageVersion=$RELEASE_VERSION
5664

5765
- name: Push
5866
run: dotnet nuget push "StackInjector/bin/Release/StackInjector.$RELEASE_VERSION.nupkg" -k ${{ secrets.NUGET_KEY }} -s https://api.nuget.org/v3/index.json

StackInjector/Core/AsyncStackWrapperCore.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ namespace StackInjector.Core
88
internal abstract partial class AsyncStackWrapperCore<T> : StackWrapperCore, IAsyncStackWrapperCore<T>
99
{
1010

11-
public event Action<T> OnElaborated;
11+
public event EventHandler<AsyncElaboratedEventArgs<T>> OnElaborated;
1212

1313

1414
// used to cancel everything
@@ -47,7 +47,7 @@ internal AsyncStackWrapperCore ( InjectionCore core, Type toRegister ) : base(co
4747

4848
public override void Dispose ()
4949
{
50-
if( !this.disposedValue )
50+
if ( !this.disposedValue )
5151
{
5252

5353
// managed resources

StackInjector/Core/AsyncStackWrapperCore.logic.cs

Lines changed: 16 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -16,63 +16,61 @@ protected internal void ReleaseListAwaiter ()
1616

1717
internal void Submit ( Task<T> work )
1818
{
19-
lock( this._listAccessLock )
19+
lock ( this._listAccessLock )
2020
this.tasks.AddLast(work);
2121

2222
// if the list was empty just an item ago, signal it's not anymore.
2323
// this limit avoids useless cross thread calls that would slow everything down.
24-
if( this.tasks.Count == 1 )
24+
if ( this.tasks.Count == 1 )
2525
this.ReleaseListAwaiter();
2626
}
2727

2828

2929
public bool AnyTaskLeft ()
3030
{
31-
lock( this._listAccessLock )
31+
lock ( this._listAccessLock )
3232
return this.tasks.Any();
3333
}
3434

3535
public bool AnyTaskCompleted ()
3636
{
37-
lock( this._listAccessLock )
37+
lock ( this._listAccessLock )
3838
return this.tasks.Any(t => t.IsCompleted);
3939
}
4040

4141
public async IAsyncEnumerable<T> Elaborated ()
4242
{
4343
this.EnsureExclusiveExecution(true);
4444

45-
while( !this.cancelPendingTasksSource.IsCancellationRequested )
45+
while ( !this.cancelPendingTasksSource.IsCancellationRequested )
4646
{
4747
// avoid deadlocks
48-
if( this.AnyTaskLeft() )
48+
if ( this.AnyTaskLeft() )
4949
{
5050
var completed = await Task.WhenAny(this.tasks).ConfigureAwait(false);
5151

52-
53-
54-
lock( this._listAccessLock )
52+
lock ( this._listAccessLock )
5553
this.tasks.Remove(completed);
5654

5755
yield return completed.Result;
5856
continue;
5957
}
6058
else
6159
{
62-
if( await this.OnNoTasksLeft().ConfigureAwait(true) )
60+
if ( await this.OnNoTasksLeft().ConfigureAwait(true) )
6361
break;
6462
}
6563
}
6664

67-
lock( this._listAccessLock )
65+
lock ( this._listAccessLock )
6866
this._exclusiveExecution = false;
6967

7068
}
7169

7270
public async Task Elaborate ()
7371
{
74-
await foreach( var res in this.Elaborated() )
75-
this.OnElaborated?.Invoke(res);
72+
await foreach ( var res in this.Elaborated() )
73+
this.OnElaborated?.Invoke(this, new AsyncElaboratedEventArgs<T>(res));
7674
}
7775

7876

@@ -85,7 +83,7 @@ Task listAwaiter ()
8583
return this._emptyListAwaiter.WaitAsync();
8684
}
8785

88-
switch( this.Settings._asyncWaitingMethod )
86+
switch ( this.Settings.Runtime._asyncWaitingMethod )
8987
{
9088

9189
case AsyncWaitingMethod.Exit:
@@ -103,7 +101,7 @@ Task listAwaiter ()
103101

104102
case AsyncWaitingMethod.Timeout:
105103
var list = listAwaiter();
106-
var timeout = Task.Delay( this.Settings._asyncWaitTime );
104+
var timeout = Task.Delay( this.Settings.Runtime._asyncWaitTime );
107105

108106
// if the timeout elapses first, then stop waiting
109107
return (await Task.WhenAny(list, timeout).ConfigureAwait(true)) == timeout;
@@ -112,12 +110,12 @@ Task listAwaiter ()
112110

113111
private void EnsureExclusiveExecution ( bool set = false )
114112
{
115-
lock( this._listAccessLock ) // reused lock
113+
lock ( this._listAccessLock ) // reused lock
116114
{
117-
if( this._exclusiveExecution )
115+
if ( this._exclusiveExecution )
118116
throw new InvalidOperationException();
119117

120-
if( set )
118+
if ( set )
121119
this._exclusiveExecution = set;
122120
}
123121
}

StackInjector/Core/Cloning/ClonedCore.cs

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,7 @@ public IAsyncStackWrapper<TEntry, TIn, TOut> ToAsyncWrapper<TEntry, TIn, TOut> (
2020
};
2121

2222
this.clonedCore.EntryType = typeof(TEntry);
23-
if( this.clonedCore.settings._registerAfterCloning )
24-
this.clonedCore.ReadAssemblies();
25-
this.clonedCore.ServeAll(cloned:true);
23+
this.clonedCore.Serve(cloned: true);
2624

2725
return wrapper;
2826
}
@@ -32,9 +30,7 @@ public IStackWrapper<T> ToWrapper<T> ()
3230
var wrapper = new StackWrapper<T>(this.clonedCore);
3331

3432
this.clonedCore.EntryType = typeof(T);
35-
if( this.clonedCore.settings._registerAfterCloning )
36-
this.clonedCore.ReadAssemblies();
37-
this.clonedCore.ServeAll(cloned:true);
33+
this.clonedCore.Serve(cloned: true);
3834

3935
return wrapper;
4036
}

StackInjector/Core/IAsyncStackWrapperCore.cs

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,23 @@
55

66
namespace StackInjector.Core
77
{
8+
/// <summary>
9+
/// The event arguments for <see cref="IAsyncStackWrapperCore{T}.OnElaborated"/>
10+
/// </summary>
11+
/// <typeparam name="T">The generic returned type of the wrapper</typeparam>
12+
public sealed class AsyncElaboratedEventArgs<T> : EventArgs
13+
{
14+
/// <summary>
15+
/// Result of the elaboration
16+
/// </summary>
17+
public T Result { get; internal set; }
18+
19+
internal AsyncElaboratedEventArgs ( T result )
20+
{
21+
this.Result = result;
22+
}
23+
}
24+
825
/// <summary>
926
/// Base interface for all asyncronous stackwrappers.
1027
/// </summary>
@@ -14,7 +31,7 @@ public interface IAsyncStackWrapperCore<T> : IStackWrapperCore
1431
/// <summary>
1532
/// called when a new element has been elaborated
1633
/// </summary>
17-
event Action<T> OnElaborated;
34+
event EventHandler<AsyncElaboratedEventArgs<T>> OnElaborated;
1835

1936

2037
/// <summary>

StackInjector/Core/IStackWrapperCore.cs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,15 @@ public interface IStackWrapperCore : IDisposable, ICloneableCore
2222
/// Find every service valid for the given class or interface.
2323
/// </summary>
2424
/// <typeparam name="T"></typeparam>
25-
/// <returns></returns>
2625
IEnumerable<T> GetServices<T> ();
2726

27+
//! description is wrong
28+
/// <summary>
29+
/// The current number of all tracked services.<br/>
30+
/// Does also include the Wrapper, so if you want all the instances
31+
/// <c>wrapper.CountServices()-1</c>
32+
/// </summary>
33+
int CountServices ();
34+
2835
}
2936
}

StackInjector/Core/injectionCore/InjectionCore.cs renamed to StackInjector/Core/InjectionCore/InjectionCore.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ internal Type EntryType
2222
set
2323
{
2424
var serviceAtt = value.GetCustomAttribute<ServiceAttribute>();
25-
if( serviceAtt != null && serviceAtt.Pattern == InstantiationPattern.AlwaysCreate )
25+
if ( serviceAtt != null && serviceAtt.Pattern == InstantiationPattern.AlwaysCreate )
2626
throw new InvalidEntryTypeException(
2727
value,
2828
$"Entry point {value.Name} cannot have {InstantiationPattern.AlwaysCreate} as instantiation pattern.",
@@ -40,6 +40,7 @@ internal Type EntryType
4040
internal InstancesHolder instances;
4141

4242
// tracks instantiated objects
43+
//todo move into instancesHolder
4344
internal readonly List<object> instancesDiff;
4445

4546
// used to lock this core on critical sections
@@ -53,7 +54,7 @@ internal InjectionCore ( StackWrapperSettings settings )
5354

5455
this.instances = new InstancesHolder();
5556

56-
if( this.settings._trackInstancesDiff )
57+
if ( this.settings.Injection._trackInstancesDiff )
5758
this.instancesDiff = new List<object>();
5859
}
5960

0 commit comments

Comments
 (0)