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

Add register aliases : RegisterEntryPoint, RegisterComponent #6

Merged
merged 5 commits into from
Jul 4, 2020

Conversation

hadashiA
Copy link
Owner

@hadashiA hadashiA commented Jul 4, 2020

Add new two register methods

RegisterEntryPoint<T>

To register entry point markers, (e.g: IInitializable, ITickable, etc) we used this until now:

builder.Register<Foo>(..).As<ITickable>();
// Or
builder.Register<Foo>(...).AsImplementedInterfaces();
  • I think this is explicit, but a bit unclear about side effects
  • This is a bit frequently, so I think it is better to have a shorter hand.

I will add following:

builder.RegisterEntryPoint<Foo>(..);

RegisterComponent<T>

In the following cases, I noticed that Inject doesn't work even though I have an instance of MonoBehaviour.

public MyMonoBehaviour : MonoBehaviour
{
    [Inject]
    public void Construct(ServiceA a) { /* ... */ }
}

public class MyInstaller : MonoInstaller
{
    [SerializeField]
    MyMonoBehaviour component;

    public void Install(IContainerBuilder builder)
    {
        builder.RegisterInstance(component);

        // Nothing to other.
    }
}

In this case, MyMonoBehaviour registered, but nothing to resolve, then nothing inject.
To fix this, Inject now works when Registering MonoBehaviour.

However, container needs to know that the registered obj is MonoBehaviour. Therefore, I added RegisterComponent instead of RegisterInstance.

    [SerializeField]
    MyMonoBehaviour component;

    // ...

    builder.RegisterComponent(component);

@hadashiA hadashiA merged commit d02967b into master Jul 4, 2020
@hadashiA hadashiA deleted the ku/add-alias branch July 4, 2020 06:47
@hadashiA
Copy link
Owner Author

hadashiA commented Jul 4, 2020

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant