diff --git a/bench/Autofac.Benchmarks/Benchmarks.cs b/bench/Autofac.Benchmarks/Benchmarks.cs index f777b71f8..2b932ca7a 100644 --- a/bench/Autofac.Benchmarks/Benchmarks.cs +++ b/bench/Autofac.Benchmarks/Benchmarks.cs @@ -28,7 +28,8 @@ public static class Benchmarks typeof(PropertyInjectionBenchmark), typeof(RootContainerResolveBenchmark), typeof(OpenGenericBenchmark), - typeof(MultiConstructorBenchmark) + typeof(MultiConstructorBenchmark), + typeof(OnActivatedBenchmark) }; } } diff --git a/bench/Autofac.Benchmarks/OnActivatedBenchmark.cs b/bench/Autofac.Benchmarks/OnActivatedBenchmark.cs new file mode 100644 index 000000000..95b595f8e --- /dev/null +++ b/bench/Autofac.Benchmarks/OnActivatedBenchmark.cs @@ -0,0 +1,36 @@ +using System; +using System.Collections.Generic; +using BenchmarkDotNet.Attributes; + +namespace Autofac.Benchmarks +{ + public class OnActivatedBenchmark + { + [Benchmark] + public void ResolveWithOnActivatedWithAction() + { + var builder = new ContainerBuilder(); + Action someAction; + builder + .RegisterType() + .OnActivated(c => + { + someAction = b => + { + b.RegisterInstance(c.Instance); + }; + }); + using var container = builder.Build(); + container.Resolve(); + } + + internal class FakeService + { + private IEnumerable _data; + public FakeService() + { + _data = new int[1000]; + } + } + } +}