Created
September 30, 2020 00:19
-
-
Save oguzhancagliyan/0133066d1cc1d77cbd1528851f9b90d9 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public interface IRepository<TModel> | |
{ | |
Task<Document> AddAsync(TModel model, CancellationToken token = default); | |
} | |
public abstract class Repository<TModel> : IRepository<TModel> | |
{ | |
protected readonly IDynamoDBContext _context; | |
protected readonly Table _table; | |
protected Repository(IDynamoDBContext context) | |
{ | |
_context = context; | |
_table = _context.GetTargetTable<TModel>(); | |
} | |
public Task<Document> AddAsync(TModel model, CancellationToken token = default) | |
{ | |
JsonSerializerOptions options = new JsonSerializerOptions | |
{ | |
IgnoreNullValues = true | |
}; | |
var modelJson = JsonSerializer.Serialize(model, options); | |
var item = Document.FromJson(modelJson); | |
var task = _table.PutItemAsync(item, token); | |
return task; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment