Exemple #1
0
        public void Start()
        {
            var builder = new ContainerBuilder();

            _core = AppCoreBuilder.Create(builder)
                    .AddModule <NCoreFileStorageModule>()
                    .AddModule(new NHibernatePostgreModule()
            {
                AssemblyMapper      = Assembly.GetExecutingAssembly(),
                ConnectionStringKey = "ncore-test-base",
                AfterConfigure      = e => {
                    FileStorageCore.Configure(e);
                    SecurityCore.Configure(e);
                }
            })
                    .AddModule(new NCoreSecurityNHibernateModule())
                    .Configure(c => {
                c.RegisterType <TestService>().As <ITestService>();
                c.RegisterType <TestRepository>().As <ITestRepository>();
            })
                    .Build();

            var service = _core.Resolve <ITestService>();

            service.AddTestRecord();
        }
Exemple #2
0
        public static AppCoreBuilder GetBuilder()
        {
            if (_coreBuilder == null)
            {
                _coreBuilder = AppCoreBuilder.Create()
                               .Configure(b => b.RegisterType <Config>().AsSelf().SingleInstance());
            }
            var cfg = ConfigurationManager.GetSection("HostConfig") as HostConfig ?? new HostConfig();

            _coreBuilder.Configure(b => b.Register(ctx => cfg).As <HostConfig>().SingleInstance());
            if (!cfg.ScanAll)
            {
                Log.Debug("Загрузка приложений из списка");
                foreach (HostedAppElement hostedApp in cfg.HostedApps)
                {
                    LoadHostedApps(hostedApp.HostedAssembly, hostedApp.LoadModules, _coreBuilder);
                }
            }
            else
            {
                Log.Debug("Загрузка всех приложений из сборок загруженных в домен");
                foreach (var assembly in AppDomain.CurrentDomain.GetAssemblies())
                {
                    LoadHostedApps(assembly, true, _coreBuilder);
                }
            }
            return(_coreBuilder);
        }
Exemple #3
0
        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 TestRavenDataStoreModule()
 {
     using (var core = AppCoreBuilder.Create()
                       .AddModule <RavenDataStoreModule>()
                       .AddModule <RavenRepositoriesModule>()
                       .Build())
     {
         using (var rep = core.Resolve <IRepositoryWithGuid <TestObject> >())
         {
             Assert.NotNull(rep);
         }
     }
 }
Exemple #5
0
        public void EmitInterfaceImplementorTest()
        {
            EmitInterfaceImplementorBase.SaveCache = false;
            var builder = new ContainerBuilder();

            builder.RegisterType <TestClass1>().AsSelf().InstancePerDependency();
            builder.RegisterType <TestClass2>().AsSelf().InstancePerLifetimeScope();

            using (var core = AppCoreBuilder
                              .Create(builder)
                              .AddModule <EmitImplementerModule>()
                              .Configure(b => b.RegisterInterfaceForEmit <IInterface>())
                              .Configure(b => b.RegisterInterfaceForEmit <IInterface1>())
                              .Configure(b => b.RegisterType <Config>().AsSelf().SingleInstance())
                              .Build())
            {
                using (var lscope = core.Scope.BeginLifetimeScope())
                {
                    var t2 = lscope.Resolve <TestClass2>();
                    t2.Val = 1;
                }

                using (var scope = core.BeginScope())
                {
                    var vaf = scope.Resolve <EmitInterfaceImplementor <IInterface> >().ImplementInterface();
                    Assert.NotNull(vaf);
                    Assert.NotNull(vaf.Test1);
                    Assert.NotNull(vaf.Test2);

                    var vaf1 = scope.Resolve <IInterface>();
                    Assert.AreNotSame(vaf, vaf1);
                    Assert.AreSame(vaf.Test2, vaf1.Test2);
                    Assert.AreNotSame(vaf.Test1, vaf1.Test1);

                    using (var vaf2 = scope.Resolve <IInterface1>())
                    {
                        Assert.AreNotSame(vaf2.Test2, vaf1.Test2);
                    }
                }
            }
        }
 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;
     }
 }