/// <summary> /// Adds <see cref="IJsonRepository{T,TKey}"/> as a service in the <see cref="IServiceCollection" />. /// </summary> /// <param name="services">The <see cref="IServiceCollection" /> to add services to.</param> /// <param name="options">An action to define options.</param> /// <param name="serviceLifetime">The lifetime with which to register the store in the container. Default is <see cref="ServiceLifetime.Scoped"/>.</param> /// <returns>The same instance of <see cref="IServiceCollection" /> for chaining.</returns> public static IServiceCollection AddJsonRepository <T, TKey>([NotNull] this IServiceCollection services, Action <JsonStoreOptions> options, ServiceLifetime serviceLifetime = ServiceLifetime.Scoped) where T : class, new() { var jsonOptions = new JsonStoreOptions(); options(jsonOptions); return(services.AddJsonRepository <T, TKey>(jsonOptions, serviceLifetime)); }
/// <summary> /// Adds <see cref="IJsonStore{T}"/> as a service in the <see cref="IServiceCollection" />. /// </summary> /// <param name="services">The <see cref="IServiceCollection" /> to add services to.</param> /// <param name="options">The options for the store.</param> /// <param name="serviceLifetime">The lifetime with which to register the store in the container. Default is <see cref="ServiceLifetime.Scoped"/>.</param> /// <returns>The same instance of <see cref="IServiceCollection" /> for chaining.</returns> public static IServiceCollection AddJsonStore <T>([NotNull] this IServiceCollection services, JsonStoreOptions options = default, ServiceLifetime serviceLifetime = ServiceLifetime.Scoped) where T : class, new() { services.TryAddOptions(options); services.Add(new ServiceDescriptor(typeof(IJsonStore <T>), typeof(JsonStore <T>), serviceLifetime)); return(services); }
/// <summary> /// Adds <see cref="IJsonStore{T}"/> and <see cref="IJsonRepository{T,TKey}"/> as a service in the <see cref="IServiceCollection" />. /// </summary> /// <param name="services">The <see cref="IServiceCollection" /> to add services to.</param> /// <param name="options">The options for the stores.</param> /// <param name="serviceLifetime">The lifetime with which to register the store in the container. Default is <see cref="ServiceLifetime.Scoped"/>.</param> /// <returns>The same instance of <see cref="IServiceCollection" /> for chaining.</returns> public static IServiceCollection AddJsonStores([NotNull] this IServiceCollection services, JsonStoreOptions options = default, ServiceLifetime serviceLifetime = ServiceLifetime.Scoped) { services.TryAddOptions(options); services.Add(new ServiceDescriptor(typeof(IJsonStore <>), typeof(JsonStore <>), serviceLifetime)); services.Add(new ServiceDescriptor(typeof(IJsonRepository <,>), typeof(JsonRepository <,>), serviceLifetime)); return(services); }
/// <summary> /// Creates a new instance of <see cref="JsonStore{T}"/> with the given options. /// </summary> /// <param name="options">The options for this store.</param> public JsonStore(JsonStoreOptions options) : base(options) { }
/// <summary> /// Creates a new instance with the given options and key. /// </summary> /// <param name="options">The options for this repository.</param> /// <param name="keyProperty">A <see cref="Func{T,TResult}" /> to get the object's key.</param> public JsonRepository(JsonStoreOptions options, Expression <Func <T, TKey> > keyProperty) : base(options) { GetKeyValue = keyProperty.Compile(); }
/// <summary> /// Creates a new instance with the given options. /// </summary> /// <param name="options">The options for this repository.</param> public JsonRepository(JsonStoreOptions options) : base(options) { var keyProperty = RepositoryKeyValidator.GetKeyProperty <T, TKey>(); GetKeyValue = keyProperty.Compile(); }