Describe the bug
Injected attributes in base class do not work in derived class if private. They do work if defined as protected or public.
To Reproduce
Steps to reproduce the behavior:
Create two monobehaviour class: ClassA and ClassB, ClassB inherit from base class ClassA.
Create two services (not monobehaviour) ServiceA and ServiceB with a simple method Execute which just print a string to console.
In ClassA define [Inject] private ServiceA _serviceA as private member field, in Start() methods just call _serviceA.Execute() method
In Class B define [Inject] private ServiceB _serviceB as private member field, in Start() methods just call base.Start() and _serviceB.Execute() method
Create Scene scope installer for both services.
Expected behaviour
Both string should be printed in the console but only the service B works.
If _serviceA is defined as [Inject] protected ServiceA _serviceA or [Inject] public ServiceA _serviceA both strings are printed.
public class ClassA : MonoBehaviour
{
[Inject] private ServiceA _serviceA;
protected virtual void Start()
{
if (_serviceA != null)
{
_serviceA?.Execute();
}
else
{
Debug.Log("service A is not injected");
}
}
}
public class ClassB : ClassA
{
[Inject] private ServiceB _serviceB;
protected override void Start()
{
base.Start();
_serviceB?.Execute();
}
}
public class ServiceA
{
public void Execute()
{
Debug.Log("I am service A");
}
}
public class ServiceB
{
public void Execute()
{
Debug.Log("I am service B");
}
}
public class DependencyInstaller : MonoBehaviour, IInstaller
{
public void InstallBindings(ContainerBuilder containerBuilder)
{
containerBuilder.AddSingleton(new ServiceA());
containerBuilder.AddSingleton(new ServiceB());
}
}
Describe the bug Injected attributes in base class do not work in derived class if private. They do work if defined as protected or public.
To Reproduce Steps to reproduce the behavior:
[Inject] private ServiceA _serviceA
as private member field, in Start() methods just call_serviceA.Execute()
method[Inject] private ServiceB _serviceB
as private member field, in Start() methods just callbase.Start()
and_serviceB.Execute()
methodExpected behaviour Both string should be printed in the console but only the service B works. If _serviceA is defined as
[Inject] protected ServiceA _serviceA
or[Inject] public ServiceA _serviceA
both strings are printed.