From Autofac 5, we will no longer provide a target for .NET 4.5. The minimum version of .NET Framework you can use Autofac with is .NET 4.6.1.
The full targeting list is now:
- netstandard2.1
#if NETCOREAPP3_0 | |
using System; | |
using System.Collections.Generic; | |
using System.Text; | |
using Xunit; | |
namespace Autofac.Test | |
{ |
public class GenericTupleDictionaryBenchmark | |
{ | |
[Params(100, 500, 1000, 2000, 5000, 10000)] | |
public int DictSize { get; set; } | |
private (Type open, Type closed)[] allTestTypes = new[] | |
{ | |
(typeof(Service1<>), typeof(Service1<string>)), | |
(typeof(Service2<>), typeof(Service2<ContainerBuilder>)), | |
(typeof(Service3<>), typeof(Service3<int>)), |
<ItemGroup Condition=" '$(TargetFramework)' == 'netstandard2.0' or '$(TargetFramework)' == 'net461' "> | |
<PackageReference Include="Microsoft.Bcl.AsyncInterfaces" Version="1.1.0-preview1.19504.10" /> | |
</ItemGroup> |
private class MyDisposableObject : IDisposable, IAsyncDisposable | |
{ | |
private SqlConnection myResource = new SqlConnection(); | |
private bool isDisposed = false; | |
public void Dispose() | |
{ | |
if (!isDisposed) | |
{ | |
isDisposed = true; |
private class MyDisposableObject : IDisposable, IAsyncDisposable | |
{ | |
private SqlConnection myResource = new SqlConnection(); | |
private bool isDisposed = false; | |
public void Dispose() | |
{ | |
if (!isDisposed) | |
{ | |
isDisposed = true; |
class BaseClassThatMightHaveChildrenWithResources : IDisposable, IAsyncDisposable | |
{ | |
public virtual void Dispose() | |
{ | |
} | |
public virtual ValueTask DisposeAsync() | |
{ | |
Dispose(); | |
return default; |
class MyObjectWithALock : IDisposable, IAsyncDisposable | |
{ | |
private SemaphoreSlim semaphore = new SemaphoreSlim(1, 1); | |
public void Dispose() | |
{ | |
semaphore.Dispose(); | |
} | |
public async ValueTask DisposeAsync() |
// Get a host builder | |
var hostBuilder = CreateHostBuilder(args); | |
// Add our service as scoped. | |
hostBuilder.ConfigureServices(srv => | |
{ | |
srv.AddScoped<MyAsyncOnlyDisposableObject>(); | |
}); | |
// Get our container |
private void NotAnAsyncMethod() | |
{ | |
var disposableObject = new MyDisposableObject(); | |
// Unpleasant | |
disposableObject.DisposeAsync().GetAwaiter().GetResult(); | |
} |