/// <summary> /// 依赖注入统一方法 /// </summary> protected async virtual ValueTask DependencyInjection() { CoreOptions = ServiceProvider.GetService <IOptions <CoreOptions <Main> > >().Value; ArchiveOptions = ServiceProvider.GetService <IOptions <ArchiveOptions <Main> > >().Value; StorageFactory = ServiceProvider.GetService <IStorageFactoryContainer>().CreateFactory(GrainType); Serializer = ServiceProvider.GetService <ISerializer>(); EventHandler = ServiceProvider.GetService <IEventHandler <PrimaryKey, State> >(); //创建归档存储器 var archiveStorageTask = StorageFactory.CreateArchiveStorage <PrimaryKey, State>(this, GrainId); if (!archiveStorageTask.IsCompletedSuccessfully) { await archiveStorageTask; } ArchiveStorage = archiveStorageTask.Result; //创建事件存储器 var eventStorageTask = StorageFactory.CreateEventStorage(this, GrainId); if (!eventStorageTask.IsCompletedSuccessfully) { await eventStorageTask; } EventStorage = eventStorageTask.Result; //创建状态存储器 var stateStorageTask = StorageFactory.CreateSnapshotStorage <PrimaryKey, State>(this, GrainId); if (!stateStorageTask.IsCompletedSuccessfully) { await stateStorageTask; } SnapshotStorage = stateStorageTask.Result; }
/// <summary> /// 依赖注入统一方法 /// </summary> protected async virtual ValueTask DependencyInjection() { CoreOptions = ServiceProvider.GetService <IOptions <CoreOptions <Children> > >().Value; ArchiveOptions = ServiceProvider.GetService <IOptions <ArchiveOptions <Children> > >().Value; StorageFactory = ServiceProvider.GetService <IStorageFactoryContainer>().CreateFactory(GrainType); ProducerContainer = ServiceProvider.GetService <IProducerContainer>(); Serializer = ServiceProvider.GetService <ISerializer>(); EventHandler = ServiceProvider.GetService <IEventHandler <PrimaryKey, State> >(); FollowUnit = ServiceProvider.GetService <IFollowUnitContainer>().GetUnit <PrimaryKey>(GrainType); //创建归档存储器 if (ArchiveOptions.On) { var archiveStorageTask = StorageFactory.CreateArchiveStorage <PrimaryKey, State>(this, GrainId); if (!archiveStorageTask.IsCompletedSuccessfully) { await archiveStorageTask; } ArchiveStorage = archiveStorageTask.Result; } //创建事件存储器 var eventStorageTask = StorageFactory.CreateEventStorage(this, GrainId); if (!eventStorageTask.IsCompletedSuccessfully) { await eventStorageTask; } EventStorage = eventStorageTask.Result; //创建状态存储器 var stateStorageTask = StorageFactory.CreateSnapshotStorage <PrimaryKey, State>(this, GrainId); if (!stateStorageTask.IsCompletedSuccessfully) { await stateStorageTask; } SnapshotStorage = stateStorageTask.Result; //创建事件发布器 var producerTask = ProducerContainer.GetProducer(this); if (!producerTask.IsCompletedSuccessfully) { await producerTask; } EventBusProducer = producerTask.Result; }