Skip to content

Commit

Permalink
Add IObjectResolver.CreateInstance
Browse files Browse the repository at this point in the history
  • Loading branch information
hadashiA committed Jan 2, 2024
1 parent 4c77e21 commit 1f2e362
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions VContainer/Assets/VContainer/Runtime/IObjectResolverExtensions.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System;
using System.Collections.Generic;
using System.Runtime.CompilerServices;
using VContainer.Internal;

namespace VContainer
{
Expand Down Expand Up @@ -34,5 +35,20 @@ public static object ResolveOrParameter(
}
return resolver.Resolve(parameterType);
}

public static object CreateInstance<T>(this IObjectResolver container) =>
container.CreateInstance(typeof(T));

public static object CreateInstance<T>(this IObjectResolver container, IReadOnlyList<IInjectParameter> parameters) =>
container.CreateInstance(typeof(T), parameters);

public static object CreateInstance(this IObjectResolver container, Type type) =>
container.CreateInstance(type, null);

public static object CreateInstance(this IObjectResolver container, Type type, IReadOnlyList<IInjectParameter> parameters)
{
var injector = InjectorCache.GetOrBuild(type);
return injector.CreateInstance(container, parameters);
}
}
}

0 comments on commit 1f2e362

Please sign in to comment.