public async Task InitializeAsync() { foreach (var singleton in SingletonProvider.GetAll()) { var content = await ContentGetter.GetAsync(singleton.ContentTypeId, singleton.KeyValues); var contentType = ContentTypeProvider.Get(singleton.ContentTypeId); if (content != null) { continue; } content = ContentInstanceCreator.Create(contentType); PrimaryKeySetter.Set(singleton.KeyValues, content); await ContentInserter.InsertAsync(content).ConfigureAwait(false); } }
public void Initialize() { foreach (var singleton in SingletonProvider.GetAll()) { var content = ContentGetter.Get <IContent>(singleton.Id, null); var contentType = ContentTypeProvider.Get(singleton.ContentTypeId); if (content != null) { if (content.ContentTypeId != contentType.Id) { throw new SingletonWithIdIsOfWrongType(singleton.Id, contentType, content.GetType(), content.ContentTypeId); } continue; } content = (IContent)Activator.CreateInstance(contentType.Type); content.Id = singleton.Id; ContentInserter.Insert(content); } }