示例#1
0
        /// <summary>
        /// 依赖注入统一方法
        /// </summary>
        protected async virtual ValueTask DependencyInjection()
        {
            CoreOptions       = ServiceProvider.GetOptionsByName <CoreOptions>(GrainType.FullName);
            ArchiveOptions    = ServiceProvider.GetOptionsByName <ArchiveOptions>(GrainType.FullName);
            Logger            = (ILogger)ServiceProvider.GetService(typeof(ILogger <>).MakeGenericType(GrainType));
            ProducerContainer = ServiceProvider.GetService <IProducerContainer>();
            Serializer        = ServiceProvider.GetService <ISerializer>();
            TypeFinder        = ServiceProvider.GetService <ITypeFinder>();
            SnapshotHandler   = ServiceProvider.GetService <ISnapshotHandler <PrimaryKey, StateType> >();
            if (SnapshotHandler == default)
            {
                throw new UnfindSnapshotHandlerException(GrainType);
            }
            ObserverUnit          = ServiceProvider.GetService <IObserverUnitContainer>().GetUnit <PrimaryKey>(GrainType);
            ObserverEventHandlers = ObserverUnit.GetAllEventHandlers();
            var configureBuilder  = (IConfigureBuilder <PrimaryKey>)ServiceProvider.GetService(typeof(IConfigureBuilder <,>).MakeGenericType(typeof(PrimaryKey), GrainType));
            var storageConfigTask = configureBuilder.GetConfig(ServiceProvider, GrainId);

            if (!storageConfigTask.IsCompletedSuccessfully)
            {
                await storageConfigTask;
            }
            var storageFactory = ServiceProvider.GetService(configureBuilder.StorageFactory) as IStorageFactory;

            //创建归档存储器
            if (ArchiveOptions.On)
            {
                var archiveStorageTask = storageFactory.CreateArchiveStorage <PrimaryKey, StateType>(storageConfigTask.Result, GrainId);
                if (!archiveStorageTask.IsCompletedSuccessfully)
                {
                    await archiveStorageTask;
                }
                ArchiveStorage = archiveStorageTask.Result;
            }
            //创建事件存储器
            var eventStorageTask = storageFactory.CreateEventStorage(storageConfigTask.Result, GrainId);

            if (!eventStorageTask.IsCompletedSuccessfully)
            {
                await eventStorageTask;
            }
            EventStorage = eventStorageTask.Result;
            //创建状态存储器
            var stateStorageTask = storageFactory.CreateSnapshotStorage <PrimaryKey, StateType>(storageConfigTask.Result, GrainId);

            if (!stateStorageTask.IsCompletedSuccessfully)
            {
                await stateStorageTask;
            }
            SnapshotStorage = stateStorageTask.Result;
            //创建事件发布器
            var producerTask = ProducerContainer.GetProducer(GrainType);

            if (!producerTask.IsCompletedSuccessfully)
            {
                await producerTask;
            }
            EventBusProducer = producerTask.Result;
        }
示例#2
0
文件: MainGrain.cs 项目: pangfd/Ray
        /// <summary>
        /// 依赖注入统一方法
        /// </summary>
        protected async virtual ValueTask DependencyInjection()
        {
            CoreOptions       = ServiceProvider.GetOptionsByName <CoreOptions>(GrainType.FullName);
            ArchiveOptions    = ServiceProvider.GetOptionsByName <ArchiveOptions>(GrainType.FullName);
            Logger            = ServiceProvider.GetService <ILogger <Grain> >();
            ProducerContainer = ServiceProvider.GetService <IProducerContainer>();
            Serializer        = ServiceProvider.GetService <ISerializer>();
            EventHandler      = ServiceProvider.GetService <IEventHandler <PrimaryKey, StateType> >();
            FollowUnit        = ServiceProvider.GetService <IFollowUnitContainer>().GetUnit <PrimaryKey>(GrainType);
            var configureBuilder  = ServiceProvider.GetService <IConfigureBuilder <PrimaryKey, Grain> >();
            var storageConfigTask = configureBuilder.GetConfig(ServiceProvider, GrainId);

            if (!storageConfigTask.IsCompletedSuccessfully)
            {
                await storageConfigTask;
            }
            var storageFactory = ServiceProvider.GetService(configureBuilder.StorageFactory) as IStorageFactory;

            //创建归档存储器
            if (ArchiveOptions.On)
            {
                var archiveStorageTask = storageFactory.CreateArchiveStorage <PrimaryKey, StateType>(storageConfigTask.Result, GrainId);
                if (!archiveStorageTask.IsCompletedSuccessfully)
                {
                    await archiveStorageTask;
                }
                ArchiveStorage = archiveStorageTask.Result;
            }
            //创建事件存储器
            var eventStorageTask = storageFactory.CreateEventStorage(storageConfigTask.Result, GrainId);

            if (!eventStorageTask.IsCompletedSuccessfully)
            {
                await eventStorageTask;
            }
            EventStorage = eventStorageTask.Result;
            //创建状态存储器
            var stateStorageTask = storageFactory.CreateSnapshotStorage <PrimaryKey, StateType>(storageConfigTask.Result, GrainId);

            if (!stateStorageTask.IsCompletedSuccessfully)
            {
                await stateStorageTask;
            }
            SnapshotStorage = stateStorageTask.Result;
            //创建事件发布器
            var producerTask = ProducerContainer.GetProducer(this);

            if (!producerTask.IsCompletedSuccessfully)
            {
                await producerTask;
            }
            EventBusProducer = producerTask.Result;
        }
示例#3
0
        /// <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;
        }
示例#4
0
 protected virtual ValueTask <IProducer> GetMQService()
 {
     return(ProducerContainer.GetProducer(this));
 }