Skip to content

Commit

Permalink
Make RegisterComponentInHierarchy available as interface
Browse files Browse the repository at this point in the history
  • Loading branch information
hadashiA committed Jan 16, 2021
1 parent a5aa425 commit 5c27e7e
Showing 1 changed file with 5 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -57,17 +57,13 @@ public static void UseEntryPoints(
configuration(entryPoints);
}

public static void UseComponents(
this IContainerBuilder builder,
Action<ComponentsBuilder> configuration)
public static void UseComponents(this IContainerBuilder builder, Action<ComponentsBuilder> configuration)
{
var components = new ComponentsBuilder(builder);
configuration(components);
}

public static RegistrationBuilder RegisterEntryPoint<T>(
this IContainerBuilder builder,
Lifetime lifetime)
public static RegistrationBuilder RegisterEntryPoint<T>(this IContainerBuilder builder, Lifetime lifetime)
{
var registrationBuilder = builder.Register<T>(lifetime);
if (typeof(T).IsSubclassOf(typeof(MonoBehaviour)))
Expand All @@ -77,27 +73,21 @@ public static RegistrationBuilder RegisterEntryPoint<T>(
return registrationBuilder.AsImplementedInterfaces();
}

public static RegistrationBuilder RegisterComponent(
this IContainerBuilder builder,
MonoBehaviour component)
public static RegistrationBuilder RegisterComponent(this IContainerBuilder builder, MonoBehaviour component)
{
var registrationBuilder = builder.RegisterInstance(component).As(typeof(MonoBehaviour), component.GetType());
builder.RegisterBuildCallback(container => container.Inject(component));
return registrationBuilder;
}

public static RegistrationBuilder RegisterComponent<TInterface>(
this IContainerBuilder builder,
TInterface component)
public static RegistrationBuilder RegisterComponent<TInterface>(this IContainerBuilder builder, TInterface component)
{
var registrationBuilder = builder.RegisterInstance(component).As(typeof(MonoBehaviour), typeof(TInterface));
builder.RegisterBuildCallback(container => container.Inject(component));
return registrationBuilder;
}

public static RegistrationBuilder RegisterComponentInHierarchy<T>(
this IContainerBuilder builder
) where T : MonoBehaviour
public static RegistrationBuilder RegisterComponentInHierarchy<T>(this IContainerBuilder builder)
{
var lifetimeScope = (LifetimeScope)builder.ApplicationOrigin;
var scene = lifetimeScope.gameObject.scene;
Expand Down

0 comments on commit 5c27e7e

Please sign in to comment.