From 7b3070768187e41d9420a14a77a0513209999383 Mon Sep 17 00:00:00 2001 From: Roger Kratz Date: Wed, 17 Feb 2021 13:48:23 +0100 Subject: [PATCH] A benchmark showing issue #1252 --- bench/Autofac.Benchmarks/Benchmarks.cs | 3 +- .../OnActivatedBenchmark.cs | 36 +++++++++++++++++++ 2 files changed, 38 insertions(+), 1 deletion(-) create mode 100644 bench/Autofac.Benchmarks/OnActivatedBenchmark.cs 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]; + } + } + } +}