There is a IDataStore interface which has this contract:
public interface IDataStore
{
Task<T> CreateEntity<T>(string entityName, string entityId, T entity);
Task<T> GetEntity<T>(string entityName, string entityId);
}
One of it's implementation is the FileSystemDataStore:
public class FileSystemDataStore : IDataStore
{
private readonly ISerializer _serializer;
public Task<T> CreateEntity<T>(string entityName, string entityId, T entity)
{
var obj = (object?)entity;
/*
* Convert entity to obj ot type Object
* Serialize obj which the _serializer service
* and store it in the file system under entityName/entityId.myExtension
*/
return Task.FromResult(entity);
}
public Task<T> GetEntity<T>(string entityName, string entityId)
{
throw new NotImplementedException();
}
}
Note the commented Code
FileSystemDataStore now has ISerializer injected, so when configuring the DI container we must explicitly provide the ISerializer implementation.
In a large application with a big dependency graph, isn't this a high risk of a mess of circular dependencies ? What is the correct way of solving this simple problem which can be applied on large projects?