The code in C# should hide a complex subsystem and only expose a certain interface.
Implementing the Facade pattern in the below way leads to the error: "Inconsistent accessibility: 'IService' is less accessible than constructor 'Facade'".
- I know that making IService(s) public solves the problem but those services should not be visible to the outside.
So the intention indeed is to have the facade publicly callable and the underlying services internal (hidden away).
Btw. using 'Clean architecture' so the Facade should be callable from the application layer's services.
Questions:
- How should this be implemented in the correct way (so that the error goes away)?
- Where actually should the IFacade and Facade code be placed, in the application layer or the infrastructure layer?
Thank you community!
public interface IFacade
{
void TestA();
void TestB();
}
public class Facade : IFacade
{
private readonly IServiceA _serviceA;
private readonly IServiceB _serviceB;
// --> HERE is the error:
public Facade(IServiceA serviceA, IServiceB serviceB)
{
_serviceA = serviceA;
_serviceB = serviceB;
}
public void TestA()
{
_service.DoA1();
_service.DoA2();
}
public void TestB()
{
_service.DoA();
}
}
internal interface IServiceA
{
void DoA1();
void DoA2();
}
internal class ServiceA : IServiceA
{
public void DoA1() { }
public void DoA2() { }
}
internal interface IServiceB
{
void DoB1();
}
internal class ServiceB : IServiceB
{
public void DoB1() { }
}