예제 #1
0
        /// <summary>
        /// 初始化。
        /// </summary>
        private void Initialize(EntityContextOptions options)
        {
            Guard.ArgumentNull(options, nameof(options));

            TrySetContextType(options);
            TrySetServiceProvider(options);
            TryPaserInstanceSetting(options);
            TryHandleConnectionTenancy(options);

            var builder = new EntityContextOptionsBuilder(options);

            OnConfiguring(builder);

            if (options.Provider == null)
            {
                throw new NotSupportedException(SR.GetString(SRKind.NotSupportDbProvider));
            }

            var contextProvider = options.GetProviderService <IContextProvider>();

            _contextService = contextProvider.CreateContextService(new ContextServiceContext(_serviceProvider, options));
        }
예제 #2
0
 /// <summary>
 /// 使用构造器进行配置。
 /// </summary>
 /// <param name="builder">构造器。</param>
 protected virtual void OnConfiguring(EntityContextOptionsBuilder builder)
 {
 }
 /// <summary>
 /// 配置 <see cref="EntityContext"/> 使用 SqlServer 数据库。
 /// </summary>
 /// <param name="connectionString"></param>
 public static void UseMongoDB(this EntityContextOptionsBuilder builder, string connectionString)
 {
     builder.Options.ContextFactory = () => new EntityContextInitializeContext(MongoDBProvider.Instance, connectionString);
 }