예제 #1
0
 private void RegisterEntityFramework(IServiceCollection services)
 {
     services.AddSingleton <IUserFactory, UserFactory>();
     services.AddTransient(provider => {
         var context = new BottomUpDddDbContext();
         context.Database.AutoTransactionsEnabled = false; // 自動トランザクションを無効にして Nested transaction にならないようにする
         return(context);
     });
     services.AddDbContext <BottomUpDddDbContext>();
     services.AddTransient <IUserRepository, EFUserRepository>();
 }
        public void TestUserIsAtomic()
        {
            var factory          = new UserFactory();
            var throwedException = false;

            try {
                Parallel.For(0, 2, _ => {
                    var context = new BottomUpDddDbContext();
                    context.Database.AutoTransactionsEnabled = false;
                    var repository = new EFUserRepository(context);
                    var app        = new UserApplicationService(factory, repository);
                    app.RegisterUser("ataro", "taro", "tanaka");
                });
            } catch (AggregateException e) {
                throwedException = true;
            }
            Assert.IsTrue(throwedException);
        }
 public EFUserRepository(BottomUpDddDbContext dbContext)
 {
     this.dbContext = dbContext;
 }