Search code examples
c#moryx

How can I access components in my module in the `IServerModuleConsole`


I have a MORYX module with a facade and some components. In my ModuleConsole I would like to access, either the facade or one of the internal components, to access functionality of the module. I tried to rely on property injection, but the property does not get filled. Is there a way to access the module or its facade from the ModuleConsole?

Example

[ServerModuleConsole]
public class ModuleConsole : IServerModuleConsole
{
    /// Injected Facade
    public ISomeFacade Facade { get; set; }

    /// Injected component (does not compile because of inconsistent accessibility)
    public ISomeComponent Component { get; set; }

    [EntrySerialize]
    public void SomeFunction() => Facade.SomeFunction();
}

Solution

  • Componets from your internal container should get injected, the facade or the module not as they are on a different level in the hierarchy.

    Usually you would not need the facade in your console, since the facade itsself should only call internal components like your console.

    So:

    public class MyFacade : IMyFacade
    {
      public ISomeComponent Component { get; set; }
    
      public void Foo() => Component.Foo();
    }
    
    public class MyConsole : IServerModuleConsole
    {
      public ISomeComponent Component { get; set; }
    
      [EntrySerialize]
      public void Foo() => Component.Foo();
    
    }