Skip to content

Add INonLazy interface for immediate instantiation via RegisterEntryPoint#846

Open
Ceeeeed wants to merge 1 commit intohadashiA:masterfrom
Ceeeeed:master
Open

Add INonLazy interface for immediate instantiation via RegisterEntryPoint#846
Ceeeeed wants to merge 1 commit intohadashiA:masterfrom
Ceeeeed:master

Conversation

@Ceeeeed
Copy link
Copy Markdown

@Ceeeeed Ceeeeed commented Apr 3, 2026

This PR introduces a new approach to support non-lazy initialization, inspired by previous discussions around the NonLazy() method. Instead of using a separate NonLazy() API, I provide an INonLazy marker interface.

Perhaps this approach will be more aligned with the repository owner's preferences. For reference, see the previous discussion: PR #574.

Key Points

  • Types implementing INonLazy will be automatically instantiated when registered via RegisterEntryPoint, ensuring immediate construction.
  • This avoids the need for empty Initialize() implementations solely to trigger early instantiation.
  • Follows the existing pattern of RegisterEntryPoint(), maintaining API consistency and clarity.
  • Includes unit tests demonstrating proper instantiation order and behavior.

Example Usage

public class MyListener : INonLazy
{
    public MyListener()
    {
        EventBus.Subscribe<MyEvent>(OnEvent);
    }

    private void OnEvent(MyEvent e)
    {
        // handle event
    }
}

// Registration
container.RegisterEntryPoint<MyListener>();
// MyListener is created immediately after container build

Introduces the INonLazy interface to support non-lazy entry point
registration in the container.
Copilot AI review requested due to automatic review settings April 3, 2026 17:28
@vercel
Copy link
Copy Markdown

vercel bot commented Apr 3, 2026

@Ceeeeed is attempting to deploy a commit to the hadashia's projects Team on Vercel.

A member of the Team first needs to authorize it.

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Adds a marker-interface-based mechanism to force eager (non-lazy) instantiation of certain entry points during EntryPointDispatcher.Dispatch(), plus a unit test demonstrating the behavior.

Changes:

  • Introduce INonLazy marker interface under VContainer.Unity.
  • Eagerly resolve INonLazy implementations at the start of EntryPointDispatcher.Dispatch().
  • Add a Unity test fixture and test case validating immediate instantiation on Build().

Reviewed changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
VContainer/Assets/VContainer/Runtime/Unity/EntryPointDispatcher.cs Forces resolution of INonLazy collection prior to running other entry point lifecycle phases.
VContainer/Assets/VContainer/Runtime/Annotations/INonLazy.cs Adds the INonLazy marker interface.
VContainer/Assets/VContainer/Runtime/Annotations/INonLazy.cs.meta Unity asset metadata for the new interface file.
VContainer/Assets/Tests/Unity/UnityContainerBuilderTest.cs Adds a test asserting that a non-lazy entry point is instantiated during container build.
VContainer/Assets/Tests/Unity/Fixtures/SampleEntryPoint.cs Adds SampleNonLazyEntryPoint test fixture implementing INonLazy.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

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.

2 participants