I need to add .OnActivated(Initialize)
to all registrations. Below is how I do this now:
builder.RegisterType<A>()
.OnActivated(Initialize);
builder.RegisterType<B>()
.OnActivated(Initialize);
builder.RegisterType<C>()
.OnActivated(Initialize);
void Initialize(IActivatedEventArgs<object> context)
{
object obj = context.Instance;
if (obj is IHasPostConstructor)
(obj as IHasPostConstructor).PostConstructor();
}
It would be great if I could simplify it to something like:
builder.RegisterType<A>();
builder.RegisterType<B>();
builder.RegisterType<C>();
builder.AllRegistrations.OnActivated(Initialize);
Is something similar possible?
Thanks