public string Name { get; set; }
void Info(string message);
public void Info(string message)
Console.WriteLine("LOG.INFO: " + message);
interface IGraphService : ICacheable<GraphModel>
class GraphService : IGraphService
public GraphService(ILogger logger)
public GraphModel Get() {
_logger.Info("GraphService.Get called.");
return new GraphModel { Name = "Just a name.." };
class Cache<T, V> where T : ICacheable<V>
IConfigurationService _configurationService;
private int callTimes = 0;
IConfigurationService configurationService,
_configurationService = configurationService;
if (!_configurationService.GetIsCacheActivated())
_result = _service.Get();
_logger.Info($"{_service.GetType()}.{nameof(_service.Get)} call already cached.");
interface IConfigurationService
bool GetIsCacheActivated();
class ConfigurationService : IConfigurationService
public bool GetIsCacheActivated() => true;
class GraphServiceCache : Cache<IGraphService, GraphModel>, IGraphService
public GraphServiceCache(
IConfigurationService configurationService,
) : base(service, configurationService, logger) { }
class GraphPrinter : IPrinter<GraphModel>
public void Print(GraphModel arg)
Console.WriteLine(arg.Name);
GraphPrinter _graphPrinter;
IGraphService _graphService;
IGraphService graphService,
GraphPrinter graphPrinter)
_graphService = graphService;
_graphPrinter = graphPrinter;
_graphPrinter.Print(_graphService.Get());
_graphPrinter.Print(_graphService.Get());
private static Container InitContext()
var container = new Container();
container.Register<ILogger, Logger>();
container.Register<IConfigurationService, ConfigurationService>();
container.Register<IGraphService, GraphServiceCache>();
container.Register<GraphPrinter>();
container.Register<MainApplication>();
public static void Main(string[] args)
var container = InitContext();
var myApp = container.GetInstance<MainApplication>();