Skip to content

Commit

Permalink
Improved code-generation for Dispose and DisposeAsync
Browse files Browse the repository at this point in the history
  • Loading branch information
NikolayPianikov committed Apr 26, 2024
1 parent 0e8ee70 commit d21df46
Show file tree
Hide file tree
Showing 20 changed files with 137 additions and 156 deletions.
2 changes: 1 addition & 1 deletion readme/Avalonia.md
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ The [project file](/samples/AvaloniaApp/AvaloniaApp.csproj) looks like this:
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Pure.DI" Version="2.1.10">
<PackageReference Include="Pure.DI" Version="2.1.11">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
Expand Down
2 changes: 1 addition & 1 deletion readme/BlazorServerApp.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ The [project file](/samples/BlazorServerApp/BlazorServerApp.csproj) looks like t
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Pure.DI" Version="2.1.10">
<PackageReference Include="Pure.DI" Version="2.1.11">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
Expand Down
2 changes: 1 addition & 1 deletion readme/BlazorWebAssemblyApp.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ The [project file](/samples/BlazorWebAssemblyApp/BlazorWebAssemblyApp.csproj) lo
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Pure.DI" Version="2.1.10">
<PackageReference Include="Pure.DI" Version="2.1.11">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
Expand Down
2 changes: 1 addition & 1 deletion readme/Console.md
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ The [project file](/samples/ShroedingersCat/ShroedingersCat.csproj) looks like t
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Pure.DI" Version="2.1.10">
<PackageReference Include="Pure.DI" Version="2.1.11">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
Expand Down
2 changes: 1 addition & 1 deletion readme/ConsoleNativeAOT.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ The [project file](/samples/ShroedingersCatNativeAOT/ShroedingersCatNativeAOT.cs
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Pure.DI" Version="2.1.10">
<PackageReference Include="Pure.DI" Version="2.1.11">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
Expand Down
2 changes: 1 addition & 1 deletion readme/ConsoleTopLevelStatements.md
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ The [project file](/samples/ShroedingersCatTopLevelStatements/ShroedingersCatTop
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Pure.DI" Version="2.1.10">
<PackageReference Include="Pure.DI" Version="2.1.11">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
Expand Down
2 changes: 1 addition & 1 deletion readme/GrpcService.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ The [project file](/samples/GrpcService/GrpcService.csproj) looks like this:
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Pure.DI" Version="2.1.10">
<PackageReference Include="Pure.DI" Version="2.1.11">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
Expand Down
2 changes: 1 addition & 1 deletion readme/Maui.md
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ The [project file](/samples/MAUIApp/MAUIApp.csproj) looks like this:
<PackageReference Include="Microsoft.Maui.Controls" Version="$(MauiVersion)"/>
<PackageReference Include="Microsoft.Maui.Controls.Compatibility" Version="$(MauiVersion)"/>
<PackageReference Include="Microsoft.Extensions.Logging.Debug" Version="8.0.0"/>
<PackageReference Include="Pure.DI" Version="2.1.10">
<PackageReference Include="Pure.DI" Version="2.1.11">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
Expand Down
2 changes: 1 addition & 1 deletion readme/MinimalWebAPI.md
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ The [project file](/samples/WebAPI/WebAPI.csproj) looks like this:
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Pure.DI" Version="2.1.10">
<PackageReference Include="Pure.DI" Version="2.1.11">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
Expand Down
2 changes: 1 addition & 1 deletion readme/WebAPI.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ The [project file](/samples/WebAPI/WebAPI.csproj) looks like this:
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Pure.DI" Version="2.1.10">
<PackageReference Include="Pure.DI" Version="2.1.11">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
Expand Down
2 changes: 1 addition & 1 deletion readme/WebApp.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ The [project file](/samples/WebApp/WebApp.csproj) looks like this:
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Pure.DI" Version="2.1.10">
<PackageReference Include="Pure.DI" Version="2.1.11">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
Expand Down
2 changes: 1 addition & 1 deletion readme/WinFormsApp.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ The [project file](/samples/WinFormsApp/WinFormsApp.csproj) looks like this:
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">

<ItemGroup>
<PackageReference Include="Pure.DI" Version="2.1.10">
<PackageReference Include="Pure.DI" Version="2.1.11">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
Expand Down
2 changes: 1 addition & 1 deletion readme/WinFormsAppNetCore.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ The [project file](/samples/WinFormsAppNetCore/WinFormsAppNetCore.csproj) looks
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Pure.DI" Version="2.1.10">
<PackageReference Include="Pure.DI" Version="2.1.11">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
Expand Down
2 changes: 1 addition & 1 deletion readme/Wpf.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ The [project file](/samples/WpfAppNetCore/WpfAppNetCore.csproj) looks like this:
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Pure.DI" Version="2.1.10">
<PackageReference Include="Pure.DI" Version="2.1.11">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
Expand Down
39 changes: 4 additions & 35 deletions readme/async-disposable-scope.md
Original file line number Diff line number Diff line change
Expand Up @@ -266,23 +266,9 @@ partial class Composition: global::System.IDisposable, global::System.IAsyncDisp
_disposablesM04D26di = new object[1];
_scopedM04D26di36_Dependency = null;
}

while (disposeIndex > 0)
{
var instance = disposables[--disposeIndex];
var disposableInstance = instance as global::System.IDisposable;
if (disposableInstance != null)
{
try
{
disposableInstance.Dispose();
}
catch (Exception exception)
{
OnDisposeException(disposableInstance, exception);
}
continue;
}

var asyncDisposableInstance = instance as global::System.IAsyncDisposable;
if (asyncDisposableInstance != null)
Expand All @@ -299,11 +285,13 @@ partial class Composition: global::System.IDisposable, global::System.IAsyncDisp
{
OnAsyncDisposeException(asyncDisposableInstance, exception);
}
continue;
continue;
}
}

}

partial void OnDisposeException<T>(T disposableInstance, Exception exception) where T : global::System.IDisposable;

public async global::System.Threading.Tasks.ValueTask DisposeAsync()
{
int disposeIndex;
Expand All @@ -316,11 +304,9 @@ partial class Composition: global::System.IDisposable, global::System.IAsyncDisp
_disposablesM04D26di = new object[1];
_scopedM04D26di36_Dependency = null;
}

while (disposeIndex > 0)
{
var instance = disposables[--disposeIndex];

var asyncDisposableInstance = instance as global::System.IAsyncDisposable;
if (asyncDisposableInstance != null)
{
Expand All @@ -332,28 +318,11 @@ partial class Composition: global::System.IDisposable, global::System.IAsyncDisp
{
OnAsyncDisposeException(asyncDisposableInstance, exception);
}
continue;
}
var disposableInstance = instance as global::System.IDisposable;
if (disposableInstance != null)
{
try
{
disposableInstance.Dispose();
}
catch (Exception exception)
{
OnDisposeException(disposableInstance, exception);
}
continue;
}
}

}

partial void OnDisposeException<T>(T disposableInstance, Exception exception) where T : global::System.IDisposable;


partial void OnAsyncDisposeException<T>(T asyncDisposableInstance, Exception exception) where T : global::System.IAsyncDisposable;

public override string ToString()
Expand Down
39 changes: 4 additions & 35 deletions readme/async-disposable-singleton.md
Original file line number Diff line number Diff line change
Expand Up @@ -201,23 +201,9 @@ partial class Composition: global::System.IDisposable, global::System.IAsyncDisp
_disposablesM04D26di = new object[1];
_singletonM04D26di36_Dependency = null;
}

while (disposeIndex > 0)
{
var instance = disposables[--disposeIndex];
var disposableInstance = instance as global::System.IDisposable;
if (disposableInstance != null)
{
try
{
disposableInstance.Dispose();
}
catch (Exception exception)
{
OnDisposeException(disposableInstance, exception);
}
continue;
}

var asyncDisposableInstance = instance as global::System.IAsyncDisposable;
if (asyncDisposableInstance != null)
Expand All @@ -234,11 +220,13 @@ partial class Composition: global::System.IDisposable, global::System.IAsyncDisp
{
OnAsyncDisposeException(asyncDisposableInstance, exception);
}
continue;
continue;
}
}

}

partial void OnDisposeException<T>(T disposableInstance, Exception exception) where T : global::System.IDisposable;

public async global::System.Threading.Tasks.ValueTask DisposeAsync()
{
int disposeIndex;
Expand All @@ -251,11 +239,9 @@ partial class Composition: global::System.IDisposable, global::System.IAsyncDisp
_disposablesM04D26di = new object[1];
_singletonM04D26di36_Dependency = null;
}

while (disposeIndex > 0)
{
var instance = disposables[--disposeIndex];

var asyncDisposableInstance = instance as global::System.IAsyncDisposable;
if (asyncDisposableInstance != null)
{
Expand All @@ -267,28 +253,11 @@ partial class Composition: global::System.IDisposable, global::System.IAsyncDisp
{
OnAsyncDisposeException(asyncDisposableInstance, exception);
}
continue;
}
var disposableInstance = instance as global::System.IDisposable;
if (disposableInstance != null)
{
try
{
disposableInstance.Dispose();
}
catch (Exception exception)
{
OnDisposeException(disposableInstance, exception);
}
continue;
}
}

}

partial void OnDisposeException<T>(T disposableInstance, Exception exception) where T : global::System.IDisposable;


partial void OnAsyncDisposeException<T>(T asyncDisposableInstance, Exception exception) where T : global::System.IAsyncDisposable;

public override string ToString()
Expand Down
39 changes: 25 additions & 14 deletions readme/disposable-singleton.md
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,6 @@ partial class Composition: global::System.IDisposable
_disposablesM04D26di = new object[1];
_singletonM04D26di36_Dependency = null;
}

while (disposeIndex > 0)
{
var instance = disposables[--disposeIndex];
Expand All @@ -212,31 +211,43 @@ partial class Composition: global::System.IDisposable
}
continue;
}
}
}

partial void OnDisposeException<T>(T disposableInstance, Exception exception) where T : global::System.IDisposable;

public async global::System.Threading.Tasks.ValueTask DisposeAsync()
{
int disposeIndex;
object[] disposables;
lock (_lockM04D26di)
{
disposeIndex = _disposeIndexM04D26di;
_disposeIndexM04D26di = 0;
disposables = _disposablesM04D26di;
_disposablesM04D26di = new object[1];
_singletonM04D26di36_Dependency = null;
}
while (disposeIndex > 0)
{
var instance = disposables[--disposeIndex];

var asyncDisposableInstance = instance as global::System.IAsyncDisposable;
if (asyncDisposableInstance != null)
var disposableInstance = instance as global::System.IDisposable;
if (disposableInstance != null)
{
try
{
var valueTask = asyncDisposableInstance.DisposeAsync();
if (!valueTask.IsCompleted)
{
valueTask.AsTask().Wait();
}
disposableInstance.Dispose();
}
catch (Exception exception)
{
OnAsyncDisposeException(asyncDisposableInstance, exception);
OnDisposeException(disposableInstance, exception);
}
continue;
continue;
}
}

}

partial void OnDisposeException<T>(T disposableInstance, Exception exception) where T : global::System.IDisposable;


partial void OnAsyncDisposeException<T>(T asyncDisposableInstance, Exception exception) where T : global::System.IAsyncDisposable;

public override string ToString()
Expand Down
Loading

0 comments on commit d21df46

Please sign in to comment.