Exemplo n.º 1
0
        public async ValueTask <IEventStorage <PrimaryKey> > CreateEventStorage <PrimaryKey>(Grain grain, PrimaryKey grainId)
        {
            var grainType = grain.GetType();

            if (configureContainer.TryGetValue(grainType, out var value) &&
                value is ConfigureBuilderWrapper <PrimaryKey, StorageConfig, ConfigParameter> builder)
            {
                var dictKey    = builder.Parameter.Singleton ? grainType.FullName : $"{grainType.FullName}-{grainId.ToString()}";
                var configTask = grainConfigDict.GetOrAdd(dictKey, async key =>
                {
                    var newConfig = builder.Generator(grain, grainId, builder.Parameter);
                    var task      = newConfig.Build();
                    if (!task.IsCompletedSuccessfully)
                    {
                        await task;
                    }
                    return(newConfig);
                });
                if (!configTask.IsCompletedSuccessfully)
                {
                    await configTask;
                }
                var storage = eventStorageDict.GetOrAdd(dictKey, key =>
                {
                    return(new EventStorage <PrimaryKey>(serviceProvider, configTask.Result));
                });
                return(storage as EventStorage <PrimaryKey>);
            }
            else
            {
                throw new NotImplementedException($"{nameof(ConfigureBuilderWrapper<PrimaryKey, StorageConfig, ConfigParameter>)} of {grainType.FullName}");
            }
        }
Exemplo n.º 2
0
 public IStorageFactory CreateFactory(Type type)
 {
     if (configureContainer.TryGetValue(type, out var value))
     {
         return(serviceProvider.GetService(value.FactoryType) as IStorageFactory);
     }
     else
     {
         throw new NotImplementedException($"{nameof(StorageFactoryContainer)} of {type.FullName}");
     }
 }