Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make RegisterComponentInHierarchy available as interface #93

Merged
merged 1 commit into from
Jan 20, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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