public void Init() { //初始化配置文件 Assembly entryAssembly = Assembly.GetExecutingAssembly(); Configuration configuration = ConfigurationExtension.GetConfigurationFromAssembly(entryAssembly); FrameworkSection.Initialize(configuration); DependencyInjectionSection.Initialize(configuration); RedisSection.Initialize(configuration); if (!ResolveMediator.ContainerBuilt) { IServiceCollection builder = ResolveMediator.GetServiceCollection(); builder.RegisterConfigs(); ResolveMediator.Build(); } DbSession dbSession = new DbSession(); dbSession.Database.EnsureCreated(); this._unitOfWork = ResolveMediator.Resolve <IUnitOfWorkStub>(); GlobalSetting.InitCurrentSessionId(); }
/// <summary> /// 初始化会话Id /// </summary> public static void InitSessionId() { lock (_Sync) { GlobalSetting.FreeCurrentSessionId(); GlobalSetting.InitCurrentSessionId(); } }
public void Init() { if (!ResolveMediator.ContainerBuilt) { IServiceCollection builder = ResolveMediator.GetServiceCollection(); builder.RegisterConfigs(); ResolveMediator.Build(); } DbSession dbSession = new DbSession(); dbSession.Database.CreateIfNotExists(); this._unitOfWork = ResolveMediator.Resolve <IUnitOfWorkStub>(); GlobalSetting.InitCurrentSessionId(); }
public void TestCreateOrder() { const int runCount = 1000; IList <Guid> sessionIds = new List <Guid>(); for (int i = 0; i < runCount; i++) { using (TransactionScope scope = new TransactionScope(TransactionScopeAsyncFlowOption.Enabled)) { GlobalSetting.InitCurrentSessionId(); sessionIds.Add(GlobalSetting.CurrentSessionId); Order order = new Order(i.ToString(), "测试单据" + i); order.Check(); EventMediator.HandleUncompletedEvents(); scope.Complete(); } } Assert.IsTrue(sessionIds.Count == runCount); Assert.IsTrue(sessionIds.Distinct().Count() == runCount); }