/// <summary>
        /// Uses the EntityFramework Core as a storage for saving and loading data.
        /// <para>
        /// Note: It means Parbad can save and load the data in different database providers
        /// such as SQL Server, MySql, Sqlite, PostgreSQL, Oracle, InMemory, etc.
        /// For more information see: https://docs.microsoft.com/en-us/ef/core/providers/.
        /// </para>
        /// <para>Note: This database is only for internal usages such as saving and loading payment information.
        /// You don't need to think about merging and using this database with your own database.
        /// The important payment information such as Tracking Number, Transaction Code, etc. will you get from the result of
        /// all payment requests.</para>
        /// </summary>
        /// <param name="builder"></param>
        /// <param name="configureEfCoreOptions">Configures the EntityFrameworkCore options for Parbad.</param>
        public static IStorageBuilder UseEfCore(this IStorageBuilder builder, Action <EntityFrameworkCoreOptions> configureEfCoreOptions)
        {
            if (builder == null)
            {
                throw new ArgumentNullException(nameof(builder));
            }
            if (configureEfCoreOptions == null)
            {
                throw new ArgumentNullException(nameof(configureEfCoreOptions));
            }

            var options = new EntityFrameworkCoreOptions();

            configureEfCoreOptions(options);

            builder.Services.Configure(configureEfCoreOptions);

            builder.Services.AddDbContext <ParbadDataContext>(dbBuilder =>
            {
                options.ConfigureDbContext?.Invoke(dbBuilder);
            });

            builder.AddStorage <EntityFrameworkCoreStorage>(ServiceLifetime.Transient);

            builder.AddStorageManager <EntityFrameworkCoreStorageManager>(ServiceLifetime.Transient);

            return(builder);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Uses the default implementation of <see cref="IStorageManager"/>.
        /// </summary>
        /// <param name="builder"></param>
        public static IStorageBuilder UseDefaultStorageManager(this IStorageBuilder builder)
        {
            if (builder == null)
            {
                throw new ArgumentNullException(nameof(builder));
            }

            return(builder.AddStorageManager <StorageManager>(ServiceLifetime.Transient));
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Uses the EntityFramework Core as a storage for saving and loading data.
        /// <para>
        /// Note: It means Parbad can save and load the data in different database providers
        /// such as SQL Server, MySql, Sqlite, PostgreSQL, Oracle, InMemory, etc.
        /// For more information see: https://docs.microsoft.com/en-us/ef/core/providers/.
        /// </para>
        /// <para>Note: This database is only for internal usages such as saving and loading payment information.
        /// You don't need to think about merging and using this database with your own database.
        /// The important payment information such as Tracking Number, Transaction Code, etc. will you get from the result of
        /// all payment requests.</para>
        /// </summary>
        /// <param name="builder"></param>
        /// <param name="configureDatabaseBuilder">Configure what database must be used and how it must be created.</param>
        public static IEntityFrameworkCoreStorageBuilder UseEntityFrameworkCore(this IStorageBuilder builder,
                                                                                Action <DbContextOptionsBuilder> configureDatabaseBuilder)
        {
            if (builder == null)
            {
                throw new ArgumentNullException(nameof(builder));
            }
            if (configureDatabaseBuilder == null)
            {
                throw new ArgumentNullException(nameof(configureDatabaseBuilder));
            }

            builder.Services.AddDbContext <ParbadDataContext>(configureDatabaseBuilder);

            builder.AddStorage <EntityFrameworkCoreStorage>(ServiceLifetime.Transient);

            builder.AddStorageManager <EntityFrameworkCoreStorageManager>(ServiceLifetime.Transient);

            return(new EntityFrameworkCoreStorageBuilder(builder.Services));
        }