Skip to content

Commit

Permalink
Merge pull request #607 from hadashiA/ku/create-instance
Browse files Browse the repository at this point in the history
Add IObjectResolver.CreateInstance
  • Loading branch information
hadashiA authored Jan 3, 2024
2 parents 4c77e21 + 1f2e362 commit 986dc8a
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);
}
}
}

1 comment on commit 986dc8a

@vercel
Copy link

@vercel vercel bot commented on 986dc8a Jan 3, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.