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

Commit

Permalink
Merge pull request #174 from JacopoWolf/rel/4
Browse files Browse the repository at this point in the history
Release 4.0.0-alpha.1
  • Loading branch information
JacopoWolf authored May 30, 2021
2 parents 47ee6a5 + dcfdc29 commit df44d35
Show file tree
Hide file tree
Showing 46 changed files with 1,294 additions and 1,326 deletions.
46 changes: 46 additions & 0 deletions .github/workflows/dotnet_pullr.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
name: .NET PR tests

# runs only on pull requests
on:
pull_request:
branches:
- 'master'
- 'rel/**'
- 'dev/**'
paths-ignore:
- '**.md'
- '**.txt'
- '**.png'


jobs:

prtest:
runs-on: ${{ matrix.os }}
env:
DOTNET_NOLOGO: true
strategy:
fail-fast: false
matrix:
os: ['ubuntu-latest','windows-latest']

steps:
- uses: actions/checkout@v2

- name: Setup .NET
uses: actions/setup-dotnet@v1
with:
dotnet-version: '5.0.x'

- name: Clean cache
run: dotnet clean --configuration Release && dotnet nuget locals all --clear

- name: Install dependencies
run: dotnet restore

- name: Build
run: dotnet build --no-restore --configuration Release

- name: Test
run: dotnet test --no-restore --configuration Release --logger "console;verbosity=detailed"

14 changes: 3 additions & 11 deletions .github/workflows/dotnet.yml → .github/workflows/dotnet_push.yml
Original file line number Diff line number Diff line change
@@ -1,27 +1,19 @@
name: .NET tests

# runs on every push on every branch
on:
push:
paths-ignore:
- '**.md'
- '**.txt'
pull_request:
branches:
- 'master'
- 'rel/**'
- 'dev/**'


jobs:

test:
runs-on: ${{ matrix.os }}
runs-on: 'ubuntu-latest'
env:
DOTNET_NOLOGO: true
strategy:
fail-fast: false
matrix:
os: ['ubuntu-latest','windows-latest']

steps:
- uses: actions/checkout@v2
Expand Down
12 changes: 10 additions & 2 deletions .github/workflows/nuget.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ on:
jobs:

test:

runs-on: ${{ matrix.os }}
env:
DOTNET_NOLOGO: true
Expand All @@ -24,18 +25,22 @@ jobs:
with:
dotnet-version: '5.0.x'

- name: Clean cache
run: dotnet clean --configuration Release && dotnet nuget locals all --clear

- name: Install dependencies
run: dotnet restore

- name: Build
run: dotnet build --no-restore --configuration Release

- name: Test
run: dotnet test --no-restore --configuration Release --logger "console;verbosity=detailed"
run: dotnet test --no-restore --configuration Release --logger "console;verbosity=detailed"



release:

needs: [test]
runs-on: ubuntu-latest

Expand All @@ -47,12 +52,15 @@ jobs:
with:
dotnet-version: '5.0.x'

- name: Install dependencies
run: dotnet restore StackInjector/StackInjector.csproj

#run: echo ::set-env name=RELEASE_VERSION::${GITHUB_REF:10}
- name: Version
run: echo "RELEASE_VERSION=${GITHUB_REF#refs/*/}" >> $GITHUB_ENV

- name: Pack
run: dotnet pack StackInjector --configuration Release -p:PackageVersion=$RELEASE_VERSION
run: dotnet pack StackInjector --no-restore --configuration Release -p:PackageVersion=$RELEASE_VERSION

- name: Push
run: dotnet nuget push "StackInjector/bin/Release/StackInjector.$RELEASE_VERSION.nupkg" -k ${{ secrets.NUGET_KEY }} -s https://api.nuget.org/v3/index.json
Expand Down
4 changes: 2 additions & 2 deletions StackInjector/Core/AsyncStackWrapperCore.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ namespace StackInjector.Core
internal abstract partial class AsyncStackWrapperCore<T> : StackWrapperCore, IAsyncStackWrapperCore<T>
{

public event Action<T> OnElaborated;
public event EventHandler<AsyncElaboratedEventArgs<T>> OnElaborated;


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

public override void Dispose ()
{
if( !this.disposedValue )
if ( !this.disposedValue )
{

// managed resources
Expand Down
34 changes: 16 additions & 18 deletions StackInjector/Core/AsyncStackWrapperCore.logic.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,63 +16,61 @@ protected internal void ReleaseListAwaiter ()

internal void Submit ( Task<T> work )
{
lock( this._listAccessLock )
lock ( this._listAccessLock )
this.tasks.AddLast(work);

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


public bool AnyTaskLeft ()
{
lock( this._listAccessLock )
lock ( this._listAccessLock )
return this.tasks.Any();
}

public bool AnyTaskCompleted ()
{
lock( this._listAccessLock )
lock ( this._listAccessLock )
return this.tasks.Any(t => t.IsCompleted);
}

public async IAsyncEnumerable<T> Elaborated ()
{
this.EnsureExclusiveExecution(true);

while( !this.cancelPendingTasksSource.IsCancellationRequested )
while ( !this.cancelPendingTasksSource.IsCancellationRequested )
{
// avoid deadlocks
if( this.AnyTaskLeft() )
if ( this.AnyTaskLeft() )
{
var completed = await Task.WhenAny(this.tasks).ConfigureAwait(false);



lock( this._listAccessLock )
lock ( this._listAccessLock )
this.tasks.Remove(completed);

yield return completed.Result;
continue;
}
else
{
if( await this.OnNoTasksLeft().ConfigureAwait(true) )
if ( await this.OnNoTasksLeft().ConfigureAwait(true) )
break;
}
}

lock( this._listAccessLock )
lock ( this._listAccessLock )
this._exclusiveExecution = false;

}

public async Task Elaborate ()
{
await foreach( var res in this.Elaborated() )
this.OnElaborated?.Invoke(res);
await foreach ( var res in this.Elaborated() )
this.OnElaborated?.Invoke(this, new AsyncElaboratedEventArgs<T>(res));
}


Expand All @@ -85,7 +83,7 @@ Task listAwaiter ()
return this._emptyListAwaiter.WaitAsync();
}

switch( this.Settings._asyncWaitingMethod )
switch ( this.Settings.Runtime._asyncWaitingMethod )
{

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

case AsyncWaitingMethod.Timeout:
var list = listAwaiter();
var timeout = Task.Delay( this.Settings._asyncWaitTime );
var timeout = Task.Delay( this.Settings.Runtime._asyncWaitTime );

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

private void EnsureExclusiveExecution ( bool set = false )
{
lock( this._listAccessLock ) // reused lock
lock ( this._listAccessLock ) // reused lock
{
if( this._exclusiveExecution )
if ( this._exclusiveExecution )
throw new InvalidOperationException();

if( set )
if ( set )
this._exclusiveExecution = set;
}
}
Expand Down
8 changes: 2 additions & 6 deletions StackInjector/Core/Cloning/ClonedCore.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,7 @@ public IAsyncStackWrapper<TEntry, TIn, TOut> ToAsyncWrapper<TEntry, TIn, TOut> (
};

this.clonedCore.EntryType = typeof(TEntry);
if( this.clonedCore.settings._registerAfterCloning )
this.clonedCore.ReadAssemblies();
this.clonedCore.ServeAll(cloned:true);
this.clonedCore.Serve(cloned: true);

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

this.clonedCore.EntryType = typeof(T);
if( this.clonedCore.settings._registerAfterCloning )
this.clonedCore.ReadAssemblies();
this.clonedCore.ServeAll(cloned:true);
this.clonedCore.Serve(cloned: true);

return wrapper;
}
Expand Down
19 changes: 18 additions & 1 deletion StackInjector/Core/IAsyncStackWrapperCore.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,23 @@

namespace StackInjector.Core
{
/// <summary>
/// The event arguments for <see cref="IAsyncStackWrapperCore{T}.OnElaborated"/>
/// </summary>
/// <typeparam name="T">The generic returned type of the wrapper</typeparam>
public sealed class AsyncElaboratedEventArgs<T> : EventArgs
{
/// <summary>
/// Result of the elaboration
/// </summary>
public T Result { get; internal set; }

internal AsyncElaboratedEventArgs ( T result )
{
this.Result = result;
}
}

/// <summary>
/// Base interface for all asyncronous stackwrappers.
/// </summary>
Expand All @@ -14,7 +31,7 @@ public interface IAsyncStackWrapperCore<T> : IStackWrapperCore
/// <summary>
/// called when a new element has been elaborated
/// </summary>
event Action<T> OnElaborated;
event EventHandler<AsyncElaboratedEventArgs<T>> OnElaborated;


/// <summary>
Expand Down
9 changes: 8 additions & 1 deletion StackInjector/Core/IStackWrapperCore.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,15 @@ public interface IStackWrapperCore : IDisposable, ICloneableCore
/// Find every service valid for the given class or interface.
/// </summary>
/// <typeparam name="T"></typeparam>
/// <returns></returns>
IEnumerable<T> GetServices<T> ();

//! description is wrong
/// <summary>
/// The current number of all tracked services.<br/>
/// Does also include the Wrapper, so if you want all the instances
/// <c>wrapper.CountServices()-1</c>
/// </summary>
int CountServices ();

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ internal Type EntryType
set
{
var serviceAtt = value.GetCustomAttribute<ServiceAttribute>();
if( serviceAtt != null && serviceAtt.Pattern == InstantiationPattern.AlwaysCreate )
if ( serviceAtt != null && serviceAtt.Pattern == InstantiationPattern.AlwaysCreate )
throw new InvalidEntryTypeException(
value,
$"Entry point {value.Name} cannot have {InstantiationPattern.AlwaysCreate} as instantiation pattern.",
Expand All @@ -40,6 +40,7 @@ internal Type EntryType
internal InstancesHolder instances;

// tracks instantiated objects
//todo move into instancesHolder
internal readonly List<object> instancesDiff;

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

this.instances = new InstancesHolder();

if( this.settings._trackInstancesDiff )
if ( this.settings.Injection._trackInstancesDiff )
this.instancesDiff = new List<object>();
}

Expand Down
Loading

0 comments on commit df44d35

Please sign in to comment.