public void AppCoreBuilderTest() { AppCoreBuilder.Create(new ContainerBuilder()).Build().Dispose(); using ( AppCore core = AppCoreBuilder.Create() .AddModule(new TestModule()) .AddModule <TestModule1>() .Configure(b => b.RegisterType <TestClass1>().AsSelf().SingleInstance()) .Build()) { using (AppScope scope = core.BeginScope()) { object r1 = scope.Resolve(typeof(TestClass1)); var r2 = scope.Resolve <TestClass1>(); Assert.AreSame(r1, r2); var t1 = scope.Resolve <TestClass2>(); using (AppScope inner = scope.BeginScope()) { var t2 = inner.Resolve <TestClass2>(); Assert.AreNotSame(t1, t2); } } } }
public void Start() { if (_scope == null) { _core1 = AppCoreBuilder .Create() .AddModule(new RavenEmbeededDataStoreModule("Data") {RunInMemory = true}) .AddModule<RavenRepositoriesModule>() .Configure(b => { // Необходимо для работы AutofacCreationConverter b.RegisterType<TestObject>().PropertiesAutowired(); //b.RegisterType<TestObject1>(); }) .Build(); _scope = _core1.BeginScope(); //AutofacCreationConverter.Container = _core.Scope; } }
public void Start() { try { Log.Debug("Начало поиска приложений"); var appTypes = _core.Resolve <IEnumerable <IHostedApp> >().ToArray(); Log.Debug("Найдено приложений: " + appTypes.Length); var appList = new List <IHostedApp>(); foreach (var hostedAppType in appTypes.Select(a => a.GetType())) { var scope = _core.BeginScope(); _appScopeList.Add(scope); var app = (IHostedApp)scope.Resolve(hostedAppType); app.AppScope = scope; appList.Add(app); _hostedScopes[app] = scope; Log.InfoFormat("Запуск приложения {0}", hostedAppType); var task = _factory.StartNew((arg) => { var curApp = (IHostedApp)arg; try { curApp.Start(); } catch (Exception ex) { Log.Error("Ошибка исполнения приложения " + curApp.GetType(), ex); } return(curApp); }, app); _appTaskList.Add(task); } Apps = appList; } catch (Exception ex) { Log.Error("Ошибка запуска приложений", ex); } Log.Info("Запущены все известные приложения"); }
public void Start() { if (_scope == null) { _core1 = AppCoreBuilder .Create() .AddModule(new RavenEmbeededDataStoreModule("Data") { RunInMemory = true }) .AddModule <RavenRepositoriesModule>() .Configure(b => { // Необходимо для работы AutofacCreationConverter b.RegisterType <TestObject>().PropertiesAutowired(); //b.RegisterType<TestObject1>(); }) .Build(); _scope = _core1.BeginScope(); //AutofacCreationConverter.Container = _core.Scope; } }
public void BasicRavenReposTest() { string realId; Guid realGuid; string refId; //using (var sess = _ds.OpenSession()) var curScope = _scope.Scope.IsRegistered <IAppScope>(); Assert.True(curScope); using (var scope = _core1.BeginScope()) using (var repos = scope.Resolve <IRepositoryWithGuid <TestObject> >()) using (var repos1 = scope.Resolve <IRepositoryWithGuid <TestObject1> >()) { var item1 = new TestObject1 { Name = "1233" }; repos1.Store(item1); var item2 = new TestObject1 { Name = "1233" }; //repos1.Store(item2); repos1.SaveChanges(); var ref1 = _scope.Resolve <Refrence <TestObject1> >(); var ref2 = _scope.Resolve <Refrence <TestObject1> >(); ref1.Object = item1; ref2.Object = item2; var item = new TestObject { Name = "123", Refrence = ref1, Refrence1 = ref2 }; repos.Store(item); repos.SaveChanges(); refId = item1.Id; realId = item.Id; realGuid = item.Guid; Assert.IsNotNullOrEmpty(realId); } using (var scope = _core1.BeginScope()) using (var repos = scope.Resolve <IRepositoryWithGuid <TestObject> >()) { TestObject item = repos.Find(realGuid); var clone = item; Assert.NotNull(repos.Find(clone.Guid)); item = repos.Find(clone.Guid); var item2 = repos.Find(new[] { realGuid }); TestObject item1 = repos.Find(realId + "123123123"); Assert.NotNull(item); //Assert.NotNull(item); //item.Refrence.RepositoryFactory = repos1; Assert.NotNull(item.Refrence); Assert.NotNull(item.Refrence.Object); Assert.AreEqual(item.Refrence.Object.Id, refId); Assert.Null(item1); repos.Delete(item); repos.SaveChanges(); } using (var repos = _scope.Resolve <IRepositoryWithGuid <TestObject> >()) using (var repos1 = _scope.Resolve <IRepositoryWithGuid <TestObject1> >()) { TestObject item = repos.Find(realId); Assert.Null(item); List <TestObject1> items = repos1.Query.ToList(); Assert.IsTrue(items.Count > 0); } var lst = new List <TestObject>(); using (var repos = _scope.Resolve <IRepositoryWithGuid <TestObject> >()) { for (int i = 0; i < 10; i++) { lst.Add(new TestObject { Name = i.ToString() }); } repos.StoreBulk(lst); repos.SaveChanges(); } using (var repos = _scope.Resolve <IRepositoryWithGuid <TestObject> >()) { List <TestObject> res = repos.Find(lst.Select(i => i.Id)).ToList(); Assert.AreEqual(res.Count, lst.Count); } }