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 #147 from JacopoWolf/dev/cleanup
Browse files Browse the repository at this point in the history
Dev/cleanup
  • Loading branch information
JacopoWolf authored Jan 2, 2021
2 parents 3081685 + 20cf352 commit c9d0c51
Show file tree
Hide file tree
Showing 46 changed files with 2,065 additions and 1,987 deletions.
16 changes: 8 additions & 8 deletions StackInjector/Attributes/IgnoredAttribute.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@
namespace StackInjector.Attributes
{

/// <summary>
/// Indicates this field or property should be ignored from injection
/// </summary>
[AttributeUsage(AttributeTargets.Property | AttributeTargets.Field, AllowMultiple = false, Inherited = true)]
public sealed class IgnoredAttribute : Attribute
{

}
/// <summary>
/// Indicates this field or property should be ignored from injection
/// </summary>
[AttributeUsage(AttributeTargets.Property | AttributeTargets.Field, AllowMultiple = false, Inherited = true)]
public sealed class IgnoredAttribute : Attribute
{

}

}
52 changes: 26 additions & 26 deletions StackInjector/Attributes/ServedAttribute.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,36 +3,36 @@

namespace StackInjector.Attributes
{
/// <summary>
/// Indicates this field or property should be injected.
/// </summary>
[AttributeUsage(AttributeTargets.Property | AttributeTargets.Field, AllowMultiple = false, Inherited = true)]
public sealed class ServedAttribute : Attribute
{
/// <summary>
/// Indicates this field or property should be injected.
/// </summary>
[AttributeUsage(AttributeTargets.Property | AttributeTargets.Field, AllowMultiple = false, Inherited = true)]
public sealed class ServedAttribute : Attribute
{

/// <summary>
/// The target version.
/// </summary>
public double TargetVersion { get; set; }
/// <summary>
/// The target version.
/// </summary>
public double TargetVersion { get; set; }

/// <summary>
/// <para>How the specified TargetVersion should be found.</para>
/// <para>could be overriden by <see cref="StackWrapperSettings"/></para>
/// </summary>
public ServedVersionTargetingMethod TargetingMethod
{
get => this._targeting;
set
{
this._targetingDefined = true;
this._targeting = value;
}
}
/// <summary>
/// <para>How the specified TargetVersion should be found.</para>
/// <para>could be overriden by <see cref="StackWrapperSettings"/></para>
/// </summary>
public ServedVersionTargetingMethod TargetingMethod
{
get => this._targeting;
set
{
this._targetingDefined = true;
this._targeting = value;
}
}


private ServedVersionTargetingMethod _targeting;
internal bool _targetingDefined;
private ServedVersionTargetingMethod _targeting;
internal bool _targetingDefined;

}
}

}
68 changes: 34 additions & 34 deletions StackInjector/Attributes/ServiceAttribute.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,43 +3,43 @@

namespace StackInjector.Attributes
{
/// <summary>
/// Allows a class to be used a service for other classes.
/// </summary>
[AttributeUsage(AttributeTargets.Class, Inherited = true, AllowMultiple = false)]
public sealed class ServiceAttribute : Attribute
{
/// <summary>
/// The version of this service.
/// </summary>
public double Version { get; set; } = -0.0;
/// <summary>
/// Allows a class to be used a service for other classes.
/// </summary>
[AttributeUsage(AttributeTargets.Class, Inherited = true, AllowMultiple = false)]
public sealed class ServiceAttribute : Attribute
{
/// <summary>
/// The version of this service.
/// </summary>
public double Version { get; set; } = -0.0;

/// <summary>
/// The instantiation pattern for this service.
/// </summary>
public InstantiationPattern Pattern
{
get => this._pattern;
set => this._pattern = value;
}
/// <summary>
/// The instantiation pattern for this service.
/// </summary>
public InstantiationPattern Pattern
{
get => this._pattern;
set => this._pattern = value;
}


/// <summary>
/// How properties and fields of this service should be injected.
/// </summary>
public ServingMethods Serving
{
get => this._serving;
set
{
this._servingDefined = true;
this._serving = value;
}
}
/// <summary>
/// How properties and fields of this service should be injected.
/// </summary>
public ServingMethods Serving
{
get => this._serving;
set
{
this._servingDefined = true;
this._serving = value;
}
}

private InstantiationPattern _pattern = InstantiationPattern.Singleton;
private ServingMethods _serving;
internal bool _servingDefined;
}
private InstantiationPattern _pattern = InstantiationPattern.Singleton;
private ServingMethods _serving;
internal bool _servingDefined;
}

}
84 changes: 43 additions & 41 deletions StackInjector/Core/AsyncStackWrapperCore.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,69 +5,71 @@

namespace StackInjector.Core
{
internal abstract partial class AsyncStackWrapperCore<T> : StackWrapperCore, IAsyncStackWrapperCore<T>
{
internal abstract partial class AsyncStackWrapperCore<T> : StackWrapperCore, IAsyncStackWrapperCore<T>
{

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


// used to cancel everything
protected internal readonly CancellationTokenSource cancelPendingTasksSource = new CancellationTokenSource();
// used to cancel everything
protected internal readonly CancellationTokenSource cancelPendingTasksSource = new CancellationTokenSource();

// exposes the token
public CancellationToken PendingTasksCancellationToken
=> this.cancelPendingTasksSource.Token;
// exposes the token
public CancellationToken PendingTasksCancellationToken
=> this.cancelPendingTasksSource.Token;

// used to lock access to tasks
private readonly object _listAccessLock = new object();
// used to lock access to tasks
private readonly object _listAccessLock = new object();

// used to endure Elaborated() and Elaborate() are called together
private bool _exclusiveExecution;
// used to endure Elaborated() and Elaborate() are called together
private bool _exclusiveExecution;

public bool IsElaborating => this._exclusiveExecution;
public bool IsElaborating => this._exclusiveExecution;

// asyncronously waited for new events if TaskList is empty
private readonly SemaphoreSlim _emptyListAwaiter = new SemaphoreSlim(0);
// asyncronously waited for new events if TaskList is empty
private readonly SemaphoreSlim _emptyListAwaiter = new SemaphoreSlim(0);

// pending tasks
protected internal LinkedList<Task<T>> tasks = new LinkedList<Task<T>>();
// pending tasks
protected internal LinkedList<Task<T>> tasks = new LinkedList<Task<T>>();


// register an event that in case the list is empty, release the empty event listener.
internal AsyncStackWrapperCore ( InjectionCore core, Type toRegister ) : base(core, toRegister) =>
this.cancelPendingTasksSource.Token.Register(this.ReleaseListAwaiter);
// register an event that in case the list is empty, release the empty event listener.
internal AsyncStackWrapperCore ( InjectionCore core, Type toRegister ) : base(core, toRegister)
{
this.cancelPendingTasksSource.Token.Register(this.ReleaseListAwaiter);
}



#region IDisposable Support
#region IDisposable Support

private bool disposedValue;
private bool disposedValue;

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

// managed resources
this.cancelPendingTasksSource.Cancel(); // cancel all pending tasks
this.ReleaseListAwaiter(); // in case it's waiting on the empty list
// managed resources
this.cancelPendingTasksSource.Cancel(); // cancel all pending tasks
this.ReleaseListAwaiter(); // in case it's waiting on the empty list

this.cancelPendingTasksSource.Dispose();
this._emptyListAwaiter.Dispose();
this.cancelPendingTasksSource.Dispose();
this._emptyListAwaiter.Dispose();


// big objects
this.tasks.Clear();
this.tasks = null;
// big objects
this.tasks.Clear();
this.tasks = null;

// clean instantiated objects
this.Core.RemoveInstancesDiff();
// clean instantiated objects
this.Core.RemoveInstancesDiff();


this.disposedValue = true;
}
}
#endregion
}
this.disposedValue = true;
}
}
#endregion
}

}
Loading

0 comments on commit c9d0c51

Please sign in to comment.