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

Injected Tickable Instance don't run Tick method #624

Open
amenonegames opened this issue Feb 10, 2024 · 2 comments
Open

Injected Tickable Instance don't run Tick method #624

amenonegames opened this issue Feb 10, 2024 · 2 comments

Comments

@amenonegames
Copy link

amenonegames commented Feb 10, 2024

Injected Tickable Instance don't run Tick method, when class is registerd as Lifetime.Transient,

Maybe because create new instance when EntryPointDispatcher runs, and register it as TickableLoopItem.

Then, only new instance's Tick medhod called in TickableLoopItem's MoveNext.
Other instance injected the classes is not called.

Following is simple testcode.
I expected display log "edited from Sample class".
But acturally displayed "empty".

    public class SampleContainerBuilder : LifetimeScope
    {
        protected override void Configure(IContainerBuilder builder)
        {

            builder.RegisterEntryPoint<SampleTick>(Lifetime.Transient)
                .AsImplementedInterfaces()
                .AsSelf();
                
            
            builder.Register<Sample>(Lifetime.Singleton)
                .AsImplementedInterfaces()
                .AsSelf();
        }
    }

    public class Sample : IStartable
    {
        
        private SampleTick _sampleTick;
        
        [Inject]
        public Sample(SampleTick sampleTick)
        {
            _sampleTick = sampleTick;
        }


        public void Start()
        {
            _sampleTick.logText = "edited from Sample class";
        }
    }


    public class SampleTick : ITickable
    {

        public string logText = "empty";
        
        public void Tick()
        {
            Debug.Log(logText);
        }
    }

== my environment==
Unity 2022.3.10f1
VContainer 1.13.2 and 1.14.0 (This occured both version)
using SourceGeneratorDLL

@LovorDev
Copy link
Contributor

Your class Sample must be registered by RegisterEntryPoint, cause it have IStartable interface

@amenonegames
Copy link
Author

amenonegames commented Feb 14, 2024

Oh, sorry for my miss registration.
But I confirmed by debugger start medhod was called in that code.

And now I tried again with following containerbuilder. But the same thing happened...

    public class SampleContainerBuilder : LifetimeScope
    {
        protected override void Configure(IContainerBuilder builder)
        {

            builder.RegisterEntryPoint<SampleTick>(Lifetime.Transient)
                .AsImplementedInterfaces()
                .AsSelf();
            
            builder.RegisterEntryPoint<Sample>();
        }
    }

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

No branches or pull requests

2 participants