diff --git a/LightweightIocContainer/Interfaces/Registrations/Fluent/IOnCreate.cs b/LightweightIocContainer/Interfaces/Registrations/Fluent/IOnCreate.cs
index ed728d3..a53bf15 100644
--- a/LightweightIocContainer/Interfaces/Registrations/Fluent/IOnCreate.cs
+++ b/LightweightIocContainer/Interfaces/Registrations/Fluent/IOnCreate.cs
@@ -15,8 +15,8 @@ public interface IOnCreate
/// This is invoked when an instance of this type is created.
/// Can be set in the by calling
///
- internal Action? OnCreateAction { get; }
- internal Func? OnCreateActionAsync { get; }
+ internal Action? OnCreateAction { get; }
+ internal Func? OnCreateActionAsync { get; }
}
///
@@ -31,7 +31,12 @@ public interface IOnCreate : IOnCreate where TImple
///
/// The
/// The current instance of this
- ITypedRegistration OnCreate(Action action);
+ ITypedRegistration OnCreate(Action action);
- ITypedRegistration OnCreateAsync(Func action);
+ ///
+ /// Pass an that will be invoked when an instance of this type is created
+ ///
+ /// The
+ /// The current instance of this
+ ITypedRegistration OnCreateAsync(Func action);
}
\ No newline at end of file
diff --git a/LightweightIocContainer/IocContainer.cs b/LightweightIocContainer/IocContainer.cs
index b3a53ed..9a87c67 100644
--- a/LightweightIocContainer/IocContainer.cs
+++ b/LightweightIocContainer/IocContainer.cs
@@ -398,7 +398,7 @@ public class IocContainer : IIocContainer, IIocResolver
if (registration is ILifestyleProvider { Lifestyle: Lifestyle.Singleton })
_singletons.Add((GetType(registration), instance));
- if (registration is IOnCreate onCreateRegistration)
+ if (registration is IOnCreate onCreateRegistration && instance is not null)
onCreateRegistration.OnCreateAction?.Invoke(instance);
return instance;
@@ -407,7 +407,7 @@ public class IocContainer : IIocContainer, IIocResolver
private async Task CreateInstanceAsync(IRegistration registration, object?[]? arguments)
{
T instance = CreateInstance(registration, arguments);
- if (registration is IOnCreate { OnCreateActionAsync: not null } onCreateRegistration)
+ if (registration is IOnCreate { OnCreateActionAsync: not null } onCreateRegistration && instance is not null)
await onCreateRegistration.OnCreateActionAsync.Invoke(instance);
return instance;
diff --git a/LightweightIocContainer/LightweightIocContainer.xml b/LightweightIocContainer/LightweightIocContainer.xml
index c90c1b9..32746d5 100644
--- a/LightweightIocContainer/LightweightIocContainer.xml
+++ b/LightweightIocContainer/LightweightIocContainer.xml
@@ -620,6 +620,13 @@
The
The current instance of this
+
+
+ Pass an that will be invoked when an instance of this type is created
+
+ The
+ The current instance of this
+
Provides a to an
diff --git a/LightweightIocContainer/Registrations/MultipleMultitonRegistration.cs b/LightweightIocContainer/Registrations/MultipleMultitonRegistration.cs
index 4d2ddbd..3afe7d4 100644
--- a/LightweightIocContainer/Registrations/MultipleMultitonRegistration.cs
+++ b/LightweightIocContainer/Registrations/MultipleMultitonRegistration.cs
@@ -43,7 +43,7 @@ internal class MultipleMultitonRegistration
/// The
/// The current instance of this
- public override ITypedRegistration OnCreate(Action action)
+ public override ITypedRegistration OnCreate(Action action)
{
foreach (IRegistration registration in Registrations)
{
diff --git a/LightweightIocContainer/Registrations/MultipleRegistration.cs b/LightweightIocContainer/Registrations/MultipleRegistration.cs
index 1ad8948..c957f75 100644
--- a/LightweightIocContainer/Registrations/MultipleRegistration.cs
+++ b/LightweightIocContainer/Registrations/MultipleRegistration.cs
@@ -62,7 +62,7 @@ internal class MultipleRegistration :
///
/// The
/// The current instance of this
- public override ITypedRegistration OnCreate(Action action)
+ public override ITypedRegistration OnCreate(Action action)
{
foreach (IRegistration registration in Registrations)
{
@@ -110,7 +110,7 @@ internal class MultipleRegistration
/// The
/// The current instance of this
- public override ITypedRegistration OnCreate(Action action)
+ public override ITypedRegistration OnCreate(Action action)
{
foreach (IRegistration registration in Registrations)
{
@@ -163,7 +163,7 @@ internal class MultipleRegistration
/// The
/// The current instance of this
- public override ITypedRegistration OnCreate(Action action)
+ public override ITypedRegistration OnCreate(Action action)
{
foreach (IRegistration registration in Registrations)
{
@@ -221,7 +221,7 @@ internal class MultipleRegistration
/// The
/// The current instance of this
- public override ITypedRegistration OnCreate(Action action)
+ public override ITypedRegistration OnCreate(Action action)
{
foreach (IRegistration registration in Registrations)
{
diff --git a/LightweightIocContainer/Registrations/TypedRegistration.cs b/LightweightIocContainer/Registrations/TypedRegistration.cs
index ae5f32a..b5652bc 100644
--- a/LightweightIocContainer/Registrations/TypedRegistration.cs
+++ b/LightweightIocContainer/Registrations/TypedRegistration.cs
@@ -34,40 +34,40 @@ internal class TypedRegistration : RegistrationBase
/// This is invoked when an instance of this type is created.
/// Can be set in the by calling
///
- private Action? OnCreateAction { get; set; }
+ private Action? OnCreateAction { get; set; }
///
/// This is invoked when an instance of this type is created.
/// Can be set in the by calling
///
- private Func? OnCreateActionAsync { get; set; }
+ private Func? OnCreateActionAsync { get; set; }
///
/// This is invoked when an instance of this type is created.
/// Can be set in the by calling
///
- Action? IOnCreate.OnCreateAction => OnCreateAction;
+ Action? IOnCreate.OnCreateAction => OnCreateAction;
///
/// This is invoked when an instance of this type is created.
/// Can be set in the by calling
///
- Func? IOnCreate.OnCreateActionAsync => OnCreateActionAsync;
+ Func? IOnCreate.OnCreateActionAsync => OnCreateActionAsync;
///
/// Pass an that will be invoked when an instance of this type is created
///
/// The
/// The current instance of this
- public virtual ITypedRegistration OnCreate(Action action)
+ public virtual ITypedRegistration OnCreate(Action action)
{
- OnCreateAction = a => action((TImplementation?) a);
+ OnCreateAction = a => action((TImplementation) a);
return this;
}
- public ITypedRegistration OnCreateAsync(Func action)
+ public ITypedRegistration OnCreateAsync(Func action)
{
- OnCreateActionAsync = a => action((TImplementation?) a);
+ OnCreateActionAsync = a => action((TImplementation) a);
return this;
}