private object Create(IGrainContext context, MethodInfo genericCreate, IPersistentStateConfiguration config) { IPersistentStateFactory factory = context.ActivationServices.GetRequiredService <IPersistentStateFactory>(); object[] args = new object[] { context, config }; return(genericCreate.Invoke(factory, args)); }
private static void ThrowMissingProviderException(IGrainContext context, IPersistentStateConfiguration cfg) { string errMsg; if (string.IsNullOrEmpty(cfg.StorageName)) { errMsg = $"No default storage provider found loading grain type {context.GrainId.Type}."; } else { errMsg = $"No storage provider named \"{cfg.StorageName}\" found loading grain type {context.GrainId.Type}."; } throw new BadGrainStorageConfigException(errMsg); }
public IPersistentState <TState> Create <TState>(IGrainContext context, IPersistentStateConfiguration cfg) { IGrainStorage storageProvider = !string.IsNullOrWhiteSpace(cfg.StorageName) ? context.ActivationServices.GetServiceByName <IGrainStorage>(cfg.StorageName) : context.ActivationServices.GetService <IGrainStorage>(); if (storageProvider == null) { ThrowMissingProviderException(context, cfg); } string fullStateName = GetFullStateName(context, cfg); var bridge = new PersistentStateBridge <TState>(fullStateName, context, storageProvider); bridge.Participate(context.ObservableLifecycle); return(bridge); }
/// <inheritdoc/> public Factory <IGrainContext, object> GetFactory(ParameterInfo parameter, PersistentStateAttribute attribute) { IPersistentStateConfiguration config = attribute; // set state name to parameter name, if not already specified if (string.IsNullOrEmpty(config.StateName)) { config = new PersistentStateConfiguration() { StateName = parameter.Name, StorageName = attribute.StorageName }; } // use generic type args to define collection type. MethodInfo genericCreate = create.MakeGenericMethod(parameter.ParameterType.GetGenericArguments()); return(context => Create(context, genericCreate, config)); }
protected virtual string GetFullStateName(IGrainContext context, IPersistentStateConfiguration cfg) { return($"{context.GrainId}.{cfg.StateName}"); }
private static void ThrowMissingProviderException(IGrainActivationContext context, IPersistentStateConfiguration cfg) { string errMsg; var grainTypeName = context.GrainType.GetParseableName(TypeFormattingOptions.LogFormat); if (string.IsNullOrEmpty(cfg.StorageName)) { errMsg = $"No default storage provider found loading grain type {grainTypeName}."; } else { errMsg = $"No storage provider named \"{cfg.StorageName}\" found loading grain type {grainTypeName}."; } throw new BadGrainStorageConfigException(errMsg); }
protected virtual string GetFullStateName(IGrainActivationContext context, IPersistentStateConfiguration cfg) { return($"{RuntimeTypeNameFormatter.Format(context.GrainType)}.{cfg.StateName}"); }