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

DI on base class? #683

Open
eviathan opened this issue Feb 6, 2021 · 0 comments
Open

DI on base class? #683

eviathan opened this issue Feb 6, 2021 · 0 comments

Comments

@eviathan
Copy link

eviathan commented Feb 6, 2021

I wonder if this is as designed and if it is can you explain a work around please? I am trying to DI my services into a base class and I want the derived implementations to also have those services injected.

Is this possible? Sorry for the wording its late and its been a busy week,

I have tried it as virtual and non virtual. I have tried calling the base init and not. Nothing seems to call the Init Method and the services are always null.

Base class:

public abstract class RenderTask : MonoBehaviour, IRenderTask
{
    private ICastleLogger _logger;
    protected ICastleLogger Logger => _logger;

    private FileService _fileService;
    protected FileService FileService => _fileService;

    private PipelineService _pipelineService;
    protected PipelineService PipelineService => _pipelineService;

    [Inject]
    public virtual void Init(ICastleLogger logger, FileService fileService, PipelineService pipelineService)
    {
        _logger = logger;
        _fileService = fileService;
        _pipelineService = pipelineService;
    }
}

Derived class

public class Split360 : RenderTask
{
    [Inject]
    public override void Init(ICastleLogger logger, FileService fileService, PipelineService pipelineService)
    {
        base.Init(logger, fileService, pipelineService);
    }
}
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

1 participant