public List<FeatureInfo> GetBindingInformations(INinjectModule module)
        {
            List<FeatureInfo> bindingsFeatureInfoList = new List<FeatureInfo>();

            IKernel kernel = new StandardKernel();
            module.OnLoad(kernel);

            List<KeyValuePair<Type, ICollection<IBinding>>> typeBindingInfo = GetBindings(kernel, module.Name);

            foreach (KeyValuePair<Type, ICollection<IBinding>> typeBinding in typeBindingInfo)
            {
                FeatureInfo bindingInterface = new FeatureInfo(typeBinding.Key, null, null, FeatureType.BindingInterface);

                foreach (IBinding binding in typeBinding.Value)
                {
                    ContextMock contextMock = new ContextMock(kernel);

                    IProvider provider = binding.ProviderCallback(contextMock);

                    FeatureInfo bindingInterfaceImpl = new FeatureInfo(provider.Type, null, null, FeatureType.BindingImpl);
                    bindingInterfaceImpl.SetBindingType(binding.Target);

                    bindingInterface.AddDependency(bindingInterfaceImpl);
                }

                bindingsFeatureInfoList.Add(bindingInterface);
            }

            return bindingsFeatureInfoList;
        }
示例#2
0
 public SubtextApplication(INinjectModule module)
 {
     if(module != null)
     {
         Bootstrapper.InitializeKernel(module);
     }
 }
示例#3
0
        public void TestPartialParametersInChild()
        {
            var modules = new INinjectModule[]
            {
                new TestModuleChilds(), 
            };

            _kernel = new StandardKernel();
            _kernel.Components.Add<IActivationStrategy, MyMonitorActivationStrategy>();

            _kernel.Load(modules);

            var main1 = _kernel.Get<SomeMainModule>();
            var main2 = _kernel.Get<SomeMainModule>();

            Assert.AreSame(main1, main2);

            var factory = _kernel.Get<IFactory<SomeTimedModule>>();
            SomeTimedModule someTimedModule1 = factory.Create();
            SomeTimedModule someTimedModule2 = factory.Create();

            Assert.AreNotSame(someTimedModule1.InnerModule, someTimedModule2.InnerModule);

            SomeTimedObject someTimedObject = someTimedModule1.ObjFactory.CreateWithParams(1);
            
            
            Assert.AreSame(someTimedObject.ModuleTimed, someTimedModule1.InnerModule);
            Assert.AreSame(someTimedObject.Module, main2);

            SomeTimedObject someTimedObject2 = someTimedModule1.ObjFactory.CreateWithParams(2);
            Assert.AreNotSame(someTimedObject2.TimedObjectInner, someTimedObject.TimedObjectInner);
            Assert.AreSame(someTimedObject2.TimedObjectInner, someTimedObject2.InnerInner.Inner);
        }
示例#4
0
        /// <summary>
        /// Punto di ingresso principale dell'applicazione.
        /// </summary>
        static void Main()
        {

            Environment.CurrentDirectory = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);

            var modules = new INinjectModule[]
                                           {
                                               new JarvisModule(), 
                                               new NHibernateModule(), 
                                               new WcfModule(),
                                               new AutoMapperModule(), 
                                           };

            IKernel kernel = new StandardKernel(modules);

            ServiceBase jarvisService = kernel.Get<JarvisServiceHost>();


            ServiceBase[] ServicesToRun;
            ServicesToRun = new ServiceBase[] 
			{ 
				jarvisService
			};
            ServiceBase.Run(ServicesToRun);

//            ((JarvisServiceHost)jarvisService).DebugOnStart(new string[]{});


        }
示例#5
0
 /// <summary>
 /// Load your modules or register your services here!
 /// </summary>
 /// <param name="kernel">The kernel.</param>
 private static void RegisterServices(IKernel kernel)
 {
     var modules = new INinjectModule[]
                     {
                         new NinjectServiceModule()
                     };
     kernel.Load(modules);
 }
 protected override IKernel CreateKernel()
 {
     var modules = new INinjectModule[]
         {
             new FooModule()
         };
     return new StandardKernel(modules); ;
 }
示例#7
0
        protected override Ninject.IKernel CreateKernel()
        {
            var modules = new INinjectModule[]
            {
                new ServiceModule()
            };

                    return new StandardKernel(modules);
        }
        private IKernel GetKernel()
        {
            var modules = new INinjectModule[]
            {
                new SampleModule()
            };

            return new StandardKernel(modules);
        }
示例#9
0
 /// <summary>
 /// Creates the kernel that will manage your application.
 /// </summary>
 /// <returns>The created kernel.</returns>
 private static IKernel CreateKernel()
 {
     var modules = new INinjectModule[]
     {
         new RepositoryModule()
     };
     var kernel = new StandardKernel(modules);
     RegisterServices(kernel);
     return kernel;
 }
示例#10
0
文件: Global.cs 项目: utunga/Tradeify
 public static void Initialize(INinjectModule configuration)
 {
     lock (_syncLock)
     {
         if (_ninjectKernel == null)
         {
             _ninjectKernel = new StandardKernel(configuration);
         }
     }
 }
示例#11
0
        public TestDaemon(Block genesisBlock = null, INinjectModule loggingModule = null, INinjectModule[] storageModules = null)
        {
            // initialize storage folder
            this.baseDirectoryCleanup = TempDirectory.CreateTempDirectory(out this.baseDirectory);

            // initialize kernel
            this.kernel = new StandardKernel();

            // add logging module
            this.kernel.Load(loggingModule ?? new ConsoleLoggingModule());

            // log startup
            this.logger = LogManager.GetCurrentClassLogger();
            this.logger.Info($"Starting up: {DateTime.Now}");

            // initialize test blocks
            this.testBlocks = new TestBlocks(genesisBlock);

            // add storage module
            this.kernel.Load(storageModules ?? new[] { new MemoryStorageModule() });

            // initialize unit test rules, allow validation methods to run
            testBlocks.Rules.ValidateTransactionAction = null;
            testBlocks.Rules.ValidationTransactionScriptAction = null;
            this.kernel.Bind<ChainType>().ToConstant(ChainType.Regtest);
            this.kernel.Bind<ICoreRules>().ToConstant(testBlocks.Rules);
            this.kernel.Bind<IChainParams>().ToConstant(testBlocks.ChainParams);

            // by default, don't run scripts in unit tests
            testBlocks.Rules.IgnoreScripts = true;

            // initialize the blockchain daemon
            this.kernel.Bind<CoreDaemon>().ToSelf().InSingletonScope();
            this.coreDaemon = this.kernel.Get<CoreDaemon>();
            try
            {
                this.coreStorage = this.coreDaemon.CoreStorage;

                // start the blockchain daemon
                this.coreDaemon.Start();

                // wait for initial work
                this.coreDaemon.WaitForUpdate();

                // verify initial state
                Assert.AreEqual(0, this.coreDaemon.TargetChainHeight);
                Assert.AreEqual(testBlocks.ChainParams.GenesisBlock.Hash, this.coreDaemon.TargetChain.LastBlock.Hash);
                Assert.AreEqual(testBlocks.ChainParams.GenesisBlock.Hash, this.coreDaemon.CurrentChain.LastBlock.Hash);
            }
            catch (Exception)
            {
                this.coreDaemon.Dispose();
                throw;
            }
        }
示例#12
0
        /// <summary>
        /// Creates the kernel that will manage your application.
        /// </summary>
        /// <returns>
        /// The created kernel.
        /// </returns>
        protected override IKernel CreateKernel()
        {
            var modules = new INinjectModule[]
            {
                new NinjectMessagingModule()
            };

            NinjectKernel = new StandardKernel(modules);

            return NinjectKernel;
        }
示例#13
0
        static void Initialize()
        {
            INinjectModule[] modules = new INinjectModule[]
            {
                new Module(),
                new Networking.Module(),
                new Helpers.Module()
            };

            _kernel = new StandardKernel(modules);
        }
        /// <summary>
        /// Create kernel with static modules.
        /// </summary>
        private static IKernel InitWithModules()
        {
            INinjectModule[] modules = new INinjectModule[]
            {
                new AutoControllerModule(Assembly.GetExecutingAssembly()),
                new ServiceModule()
            };

            var kernel = new StandardKernel();

            return kernel;
        }
        public NinjectDependencyResolver()
        {
            // add more ninject module
            var modules = new INinjectModule[]
                              {
                                 new RepositoryModule(),
                                 new LoggingModule(),
                                 new AccountModule()
                              };

            kernel = new StandardKernel(modules);
        }
示例#16
0
        /// <summary>
        /// Load your modules or register your services here!
        /// </summary>
        /// <param name="kernel">The kernel.</param>
        private static void RegisterServices(IKernel kernel)
        {
            // Set dependency injection bindings
            var modules = new INinjectModule[]
                {
                    new getsetcode.Business.Binders.Default(),
                    new getsetcode.Presentation.Binders.Default(),
                    new getsetcode.Web.Binders.Default()
                };

            kernel.Load(modules);
        }
示例#17
0
        /// <summary>
        /// Load your modules or register your services here!
        /// </summary>
        /// <param name="kernel">The kernel.</param>
        private static void RegisterServices(IKernel kernel)
        {
            var modules = new INinjectModule[]
            {
                new Modules.NLogModule(),
                new Modules.RavenModule(),
                new Modules.RepositoryModule(),
                new Modules.ServiceModule(),
                new Modules.SimpleCryptoModule()
            };

            kernel.Load(modules);
        }
        /// <summary>
        /// Creates the kernel that will manage your application.
        /// </summary>
        /// <returns>The created kernel.</returns>
        private static IKernel CreateKernel()
        {
            var modules = new INinjectModule[]{
//                new DalNinjectModule()
            };

            var kernel = new StandardKernel(modules);
            kernel.Bind<Func<IKernel>>().ToMethod(ctx => () => new Bootstrapper().Kernel);
            kernel.Bind<IHttpModule>().To<HttpApplicationInitializationHttpModule>();

            RegisterServices(kernel);
            return kernel;
        }
示例#19
0
文件: server.cs 项目: arunappulal/all
    public static void Main(string[] args)
    {
        var modules = new INinjectModule[] { new DomasNinjectModule() };
        KernelContainer.Kernel = new StandardKernel(modules);

        var binding = new BasicHttpBinding();
        var address = new Uri("http://127.0.0.1:8888");
        var host = new NinjectServiceHost(typeof(DomasService));
        host.AddServiceEndpoint(typeof(IDomasService), binding, address);
        host.Open();
        Console.WriteLine("Press enter to stop..");
        Console.ReadLine();
        host.Close();
    }
        /// <summary>
        /// Initializes a new instance of the ViewModelLocator class.
        /// </summary>
        public ViewModelLocator()
        {
            var modules = new INinjectModule[]
                              {
                                  new LocationServiceModule(),
                                  new ViewModelsModule(ViewModelBase.IsInDesignModeStatic),
                                  new BingMapsModule(), 
                                  new AutoMapperModule(), 
                              };

            
            _container = new StandardKernel(modules);
           
            ServiceLocator.SetLocatorProvider(() => new NinjectServiceLocator(_container));
        }
示例#21
0
        public static void Reset()
        {
//            _generator = null;
            try {
                Kernel.Dispose();
            }
            catch {}
            try {
                Kernel = null;
            }
            catch {}
            _ninjectModule = null;
            _initFlag = false;
            // _initFlag = true;
        }
示例#22
0
        /// <summary>
        /// Generates a message saying that a module with the same name is already loaded.
        /// </summary>
        /// <param name="newModule">The new module.</param>
        /// <param name="existingModule">The existing module.</param>
        /// <returns>The exception message.</returns>
        public static string ModuleWithSameNameIsAlreadyLoaded(INinjectModule newModule, INinjectModule existingModule)
        {
            using (var sw = new StringWriter())
            {
                sw.WriteLine("Error loading module '{0}' of type {1}", newModule.Name, newModule.GetType().Format());
                sw.WriteLine("Another module (of type {0}) with the same name has already been loaded", existingModule.GetType().Format());

                sw.WriteLine("Suggestions:");
                sw.WriteLine("  1) Ensure that you have not accidentally loaded the same module twice.");
                #if !SILVERLIGHT
                sw.WriteLine("  2) If you are using automatic module loading, ensure you have not manually loaded a module");
                sw.WriteLine("     that may be found by the module loader.");
                #endif

                return sw.ToString();
            }
        }
        public void TestBindingParameters()
        {
            var modules = new INinjectModule[]
            {
                new TestModuleChilds(), 
            };

            _kernel = new StandardKernel();
            _kernel.Components.Add<IActivationStrategy, MyMonitorActivationStrategy>();

            _kernel.Load(modules);

            var factory = _kernel.Get<IBindingFactory<SomeTimedModule>>();
            SomeTimedModule someTimedModule1 = factory.CreateWithBindings(new SomeObject(3));
            Assert.AreEqual(someTimedModule1.SomeObject.Parameter, 
                someTimedModule1.InnerModule.SomeObject.Parameter);
        }
示例#24
0
        internal static IKernel BuildKernel()
        {
            if (_kernel != null)
            {
                return(_kernel);
            }

            var modules = new INinjectModule[]
            {
                new BLLNinjectModule(),
                new WebApiNinjectModule()
            };

            _kernel = new StandardKernel(modules);

            return(_kernel);
        }
示例#25
0
        public void TestPartialParameters()
        {
            var modules = new INinjectModule[]
            {
                new TestModule(), 
            };

            _kernel = new StandardKernel();
            _kernel.Components.Add<IActivationStrategy, MyMonitorActivationStrategy>();

            _kernel.Load(modules);

            var factory = _kernel.Get<IFactory<SomeObject>>();
            SomeObject withParams = factory.CreateWithParams(1);
            withParams.Parameter.ShouldEqual(1);
            withParams.Module.ShouldNotBeNull();
        }
示例#26
0
        public void SetupDependencyInjection()
        {
            var modules = new INinjectModule[]
            {
                new VisualMutatorModule(),
                //   new GuiNinjectModule(new VisualStudioConnection(_package)),
            };



            _kernel = new StandardKernel();
            _kernel.Components.Add <IActivationStrategy, MyMonitorActivationStrategy>();



            _kernel.Load(modules);
        }
        public void TestFixtureSetup()
        {
            File.Delete("jarvis.sqlite3");
            var modules = new INinjectModule[]
                              {
                                  new NHibernateModule(),
                                  new JarvisModule(),
                                  new AutoMapperModule(),
                                  new WcfModule(),
                              };
            var kernel = new StandardKernel(modules);

            _sut = kernel.Get<JarvisWcfService>();
            _mappingEngine = kernel.Get<IMappingEngine>();

            
        }
        /// <summary>
        /// Generates a message saying that a module with the same name is already loaded.
        /// </summary>
        /// <param name="newModule">The new module.</param>
        /// <param name="existingModule">The existing module.</param>
        /// <returns>The exception message.</returns>
        public static string ModuleWithSameNameIsAlreadyLoaded(INinjectModule newModule, INinjectModule existingModule)
        {
            using (var sw = new StringWriter())
            {
                sw.WriteLine("Error loading module '{0}' of type {1}", newModule.Name, newModule.GetType().Format());
                sw.WriteLine("Another module (of type {0}) with the same name has already been loaded", existingModule.GetType().Format());

                sw.WriteLine("Suggestions:");
                sw.WriteLine("  1) Ensure that you have not accidentally loaded the same module twice.");
                #if !SILVERLIGHT
                sw.WriteLine("  2) If you are using automatic module loading, ensure you have not manually loaded a module");
                sw.WriteLine("     that may be found by the module loader.");
                #endif

                return(sw.ToString());
            }
        }
示例#29
0
        /// <summary>
        /// Attempts to load the module instance to the kernel
        /// </summary>
        /// <param name="kernel"></param>
        /// <param name="module">Module to load</param>
        /// <returns>IKernel instance with module loaded</returns>
        /// <exception cref="Exception">Thrown if unable to load the module</exception>
        /// <example>
        /// kernel.WithModule(new LoggingModule());
        /// </example>
        public static IKernel WithModule(this IKernel kernel, INinjectModule module)
        {
            if (!kernel.HasModule(module.Name))
            {
                try
                {
                    kernel.Load(module);
                }
                catch (Exception ex)
                {
                    var error = string.Format("Unable to load module '{0}' see inner exception.", module.Name);
                    throw new Exception(error, ex);
                }
            }

            return(kernel);
        }
示例#30
0
        /// <summary>
        /// Creates the kernel that will manage your application.
        /// </summary>
        /// <returns>The created kernel.</returns>
        private static IKernel CreateKernel()
        {
            var modules = new INinjectModule[] { new ServiceModule("KnowledgeDB") };
            var kernel  = new StandardKernel(modules);

            try
            {
                RegisterServices(kernel);
                GlobalConfiguration.Configuration.DependencyResolver = new NinjectDependencyResolver(kernel);
                return(kernel);
            }
            catch
            {
                kernel.Dispose();
                throw;
            }
        }
示例#31
0
        /// <summary>
        /// Creates the kernel that will manage your application.
        /// </summary>
        /// <returns>The created kernel.</returns>
        private static IKernel CreateKernel()
        {
            var modules = new INinjectModule[] { new ServiceModule("DefaultConnection") };
            var kernel  = new StandardKernel(modules);

            try
            {
                kernel.Bind <Func <IKernel> >().ToMethod(ctx => () => new Bootstrapper().Kernel);
                kernel.Bind <IHttpModule>().To <HttpApplicationInitializationHttpModule>();
                RegisterServices(kernel);
                return(kernel);
            }
            catch
            {
                kernel.Dispose();
                throw;
            }
        }
        public void TestBindingParameters()
        {
            var modules = new INinjectModule[]
            {
                new TestModuleChilds(),
            };

            _kernel = new StandardKernel();
            _kernel.Components.Add <IActivationStrategy, MyMonitorActivationStrategy>();

            _kernel.Load(modules);

            var             factory          = _kernel.Get <IBindingFactory <SomeTimedModule> >();
            SomeTimedModule someTimedModule1 = factory.CreateWithBindings(new SomeObject(3));

            Assert.AreEqual(someTimedModule1.SomeObject.Parameter,
                            someTimedModule1.InnerModule.SomeObject.Parameter);
        }
示例#33
0
        /// <summary>
        /// Creates the kernel that will manage your application.
        /// </summary>
        /// <returns>The created kernel.</returns>
        private static IKernel CreateKernel()
        {
            var modules = new INinjectModule[] {new ServiceModule("SqlServerMotorDepot")};
            var kernel = new StandardKernel(modules);
            try
            {
                kernel.Bind<Func<IKernel>>().ToMethod(ctx => () => new Bootstrapper().Kernel);
                kernel.Bind<IHttpModule>().To<HttpApplicationInitializationHttpModule>();

                RegisterServices(kernel);
                return kernel;
            }
            catch
            {
                kernel.Dispose();
                throw;
            }
        }
        public void TestPartialParameters()
        {
            var modules = new INinjectModule[]
            {
                new TestModule(), 
            };

            _kernel = new StandardKernel();
            _kernel.Components.Add<IActivationStrategy, MyMonitorActivationStrategy>();

            _kernel.Load(modules);

            var factory = _kernel.Get<IFactory<SomeMainModule>>();
            for (int i = 0; i < 1000000; i++)
            {
                factory.Create();
            }
        }
示例#35
0
        public void TestPartialParameters()
        {
            var modules = new INinjectModule[]
            {
                new TestModule(),
            };

            _kernel = new StandardKernel();
            _kernel.Components.Add <IActivationStrategy, MyMonitorActivationStrategy>();

            _kernel.Load(modules);

            var        factory    = _kernel.Get <IFactory <SomeObject> >();
            SomeObject withParams = factory.CreateWithParams(1);

            withParams.Parameter.ShouldEqual(1);
            withParams.Module.ShouldNotBeNull();
        }
示例#36
0
        public void ModuleShouldInitialize()
        {
            var modules = new INinjectModule[1]
            {
                new TestModule()
            };

            using (var bootstrapper = new Bootstrapper(modules))
                using (var kernel = bootstrapper.Run())
                {
                    foreach (var module in modules)
                    {
                        var testModule = module as TestModule;
                        Assert.IsTrue(testModule != null && testModule.IsLoaded);
                        Assert.IsTrue(testModule.ModuleLogger != null);
                    }
                }
        }
        private static IKernel CreateKernel()
        {
            var modules = new INinjectModule[] { new ServiceModule("ShopParser") };
            var kernel  = new StandardKernel(modules);

            try
            {
                kernel.Bind <Func <IKernel> >().ToMethod(ctx => () => new Bootstrapper().Kernel);
                kernel.Bind <IHttpModule>().To <HttpApplicationInitializationHttpModule>();
                RegisterServices(kernel);
                GlobalConfiguration.Configuration.DependencyResolver = new Ninject.Web.WebApi.NinjectDependencyResolver(kernel);
                return(kernel);
            }
            catch
            {
                kernel.Dispose();
                throw;
            }
        }
示例#38
0
        /// <summary>
        /// Creates the kernel that will manage your application.
        /// </summary>
        /// <returns>The created kernel.</returns>
        private static IKernel CreateKernel()
        {
            var modules = new INinjectModule[] { new BLLModule("MuseumContext"), new AutoMapperModule() };
            var kernel  = new StandardKernel(modules);

            try
            {
                kernel.Bind <Func <IKernel> >().ToMethod(ctx => () => new Bootstrapper().Kernel);
                kernel.Bind <IHttpModule>().To <HttpApplicationInitializationHttpModule>();
                RegisterServices(kernel);
                GlobalConfiguration.Configuration.DependencyResolver = new CustomeNinjectDependencyResolver(kernel);
                return(kernel);
            }
            catch
            {
                kernel.Dispose();
                throw;
            }
        }
示例#39
0
        public static IKernel WithModule <TModule>(this IKernel kernel) where TModule : INinjectModule, new()
        {
            INinjectModule module = null;

            try
            {
                module = (INinjectModule)Activator.CreateInstance(typeof(TModule));
                if (!kernel.HasModule(module.Name))
                {
                    kernel.Load <TModule>();
                }
            }
            catch (Exception ex)
            {
                var error = $"Unable to load module '{module.Name}' see inner exception.";
                throw new Exception(error, ex);
            }
            return(kernel);
        }
示例#40
0
        protected override IKernel CreateKernel()
        {
            var modules = new INinjectModule[]
            {
                new PersistenceModule(),
                new TinyMapperModule()
            };

            var kernel = new StandardKernel();

            kernel.Load(modules);

            kernel.Bind <Func <IKernel> >().ToMethod(ctx => () => new Bootstrapper().Kernel);
            kernel.Bind <IHttpModule>().To <HttpApplicationInitializationHttpModule>();
            // register the dependency resolver passing the kernel container
            GlobalConfiguration.Configuration.DependencyResolver = new NinjectDependencyResolver(kernel);

            return(new StandardKernel());
        }
示例#41
0
        protected void Application_Start()
        {
            AreaRegistration.RegisterAllAreas();
            FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
            RouteConfig.RegisterRoutes(RouteTable.Routes);
            BundleConfig.RegisterBundles(BundleTable.Bundles);

            var modules = new INinjectModule[]
            {
                new RepositoryModule(),
                new MapperModule(),
                new UnitOfWorkModule(),
                new DataContextModule()
            };

            var kernel = new StandardKernel(modules);                              // регистрация в ядре (kernel) всех модулей

            DependencyResolver.SetResolver(new NinjectDependencyResolver(kernel)); // добавление решения для зависимостей в asp.net mvc
        }
        /// <summary>
        /// Creates the kernel that will manage your application.
        /// </summary>
        /// <returns>The created kernel.</returns>
        private static IKernel CreateKernel()
        {
            var modules = new INinjectModule[] { new ServiceModule(System.Configuration.ConfigurationManager.ConnectionStrings["ScheduleCinemaDb"].ConnectionString) };
            var kernel  = new StandardKernel(modules);

            try
            {
                kernel.Bind <Func <IKernel> >().ToMethod(ctx => () => new Bootstrapper().Kernel);
                kernel.Bind <IHttpModule>().To <HttpApplicationInitializationHttpModule>();

                RegisterServices(kernel);
                return(kernel);
            }
            catch
            {
                kernel.Dispose();
                throw;
            }
        }
示例#43
0
        /// <summary>
        /// Creates the kernel that will manage your application.
        /// </summary>
        /// <returns>The created kernel.</returns>
        private static IKernel CreateKernel()
        {
            // устанавливаем строку подключения
            var modules = new INinjectModule[] { new ServiceModule("DefaultConnection") };
            var kernel = new StandardKernel(modules);
            try
            {
            kernel.Bind<Func<IKernel>>().ToMethod(ctx => () => new Bootstrapper().Kernel);
            kernel.Bind<IHttpModule>().To<HttpApplicationInitializationHttpModule>();

            RegisterServices(kernel);
            return kernel;
            }
            catch
            {
            kernel.Dispose();
            throw;
            }
        }
示例#44
0
        public void TestPartialParameters()
        {
            var modules = new INinjectModule[]
            {
                new TestModule(),
            };

            _kernel = new StandardKernel();
            _kernel.Components.Add <IActivationStrategy, MyMonitorActivationStrategy>();

            _kernel.Load(modules);

            var factory = _kernel.Get <IFactory <SomeMainModule> >();

            for (int i = 0; i < 1000000; i++)
            {
                factory.Create();
            }
        }
示例#45
0
        private static IKernel CreateKernel()
        {
            var modules = new INinjectModule[] { new InfrastructureModule("GameStoreDb", "NorthwindDb"), new ApplicationModule() };
            var kernel  = new StandardKernel(modules);

            try
            {
                kernel.Bind <Func <IKernel> >().ToMethod(ctx => () => new Bootstrapper().Kernel);
                kernel.Bind <IHttpModule>().To <HttpApplicationInitializationHttpModule>();

                RegisterServices(kernel);
                return(kernel);
            }
            catch
            {
                kernel.Dispose();
                throw;
            }
        }
示例#46
0
        public void ModulesContainedInAssembliesAreLoaded()
        {
            Assembly assembly = Assembly.GetExecutingAssembly();

            this.Kernel.Load(assembly);

            var modules = this.Kernel.GetModules().ToArray();

            INinjectModule testModule  = modules.SingleOrDefault(module => module.GetType() == typeof(TestModule));
            INinjectModule testModule2 = modules.SingleOrDefault(module => module.GetType() == typeof(TestModule2));
            INinjectModule testModule3 = modules.SingleOrDefault(module => module.GetType() == typeof(OtherFakes.TestModule));

            testModule.ShouldNotBeNull();
            testModule2.ShouldNotBeNull();
            testModule3.ShouldNotBeNull();
            testModule.Kernel.ShouldBe(this.Kernel);
            testModule2.Kernel.ShouldBe(this.Kernel);
            testModule3.Kernel.ShouldBe(this.Kernel);
        }
示例#47
0
        protected void Application_Start()
        {
            Mapper.Initialize(cfg => {
                cfg.AddProfile <BLLProfile>();
                cfg.AddProfile <WebAPIProfile>();
            });
            Mapper.Configuration.AssertConfigurationIsValid();
            AreaRegistration.RegisterAllAreas();
            GlobalConfiguration.Configure(WebApiConfig.Register);
            FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
            RouteConfig.RegisterRoutes(RouteTable.Routes);
            var modules = new INinjectModule[]
            {
                new WebApiNinjectModule(),
                new BLL.Services.BllNinjectModule()
            };
            IKernel kernel = new StandardKernel(modules);

            GlobalConfiguration.Configuration.DependencyResolver = new NinjectResolver(kernel);
        }
示例#48
0
        /// <summary>
        /// Creates the kernel that will manage your application.
        /// </summary>
        /// <returns>The created kernel.</returns>
        private static IKernel CreateKernel()
        {
            var modules = new INinjectModule[] { new DIResolver("RecruitingAgencyDB") };

            Kernel = new StandardKernel(modules);
            try
            {
                Kernel.Bind <Func <IKernel> >().ToMethod(ctx => () => new Bootstrapper().Kernel);
                Kernel.Bind <IHttpModule>().To <HttpApplicationInitializationHttpModule>();

                RegisterServices(Kernel);
                GlobalConfiguration.Configuration.DependencyResolver = new NinjectDependencyResolver(Kernel);
                return(Kernel);
            }
            catch
            {
                Kernel.Dispose();
                throw;
            }
        }
示例#49
0
        /// <summary>
        /// Creates the kernel that will manage your application.
        /// </summary>
        /// <returns>The created kernel.</returns>
        private static IKernel CreateKernel()
        {
            // устанавливаем строку подключения
            var modules = new INinjectModule[] { new ServiceModule("data source=DESKTOP-E43P3CL\\SQLEXPRESS;initial catalog=MessengerDb;integrated security=True;MultipleActiveResultSets=True;App=EntityFramework") };
            var kernel  = new StandardKernel(modules);

            try
            {
                kernel.Bind <Func <IKernel> >().ToMethod(ctx => () => new Bootstrapper().Kernel);
                kernel.Bind <IHttpModule>().To <HttpApplicationInitializationHttpModule>();

                RegisterServices(kernel);
                return(kernel);
            }
            catch
            {
                kernel.Dispose();
                throw;
            }
        }
示例#50
0
        /// <summary>
        /// Creates the kernel that will manage your application.
        /// </summary>
        /// <returns>The created kernel.</returns>
        private static IKernel CreateKernel()
        {
            ConfigurationSettingsEntity configurationSettings = new ConfigurationSettingsEntity(ConfigurationManager.AppSettings);
            var modules = new INinjectModule[] { new DependencyResolution.DependencyRegistrar(configurationSettings) };
            var kernel  = new StandardKernel(modules);

            try
            {
                kernel.Bind <Func <IKernel> >().ToMethod(ctx => () => new Bootstrapper().Kernel);
                kernel.Bind <IHttpModule>().To <HttpApplicationInitializationHttpModule>();

                GlobalConfiguration.Configuration.DependencyResolver = new NinjectDependencyResolver(kernel);
                return(kernel);
            }
            catch
            {
                kernel.Dispose();
                throw;
            }
        }
        /// <summary>
        /// Creates the kernel that will manage your application.
        /// </summary>
        /// <returns>The created kernel.</returns>
        private static IKernel CreateKernel()
        {
            var modules = new INinjectModule[] { new DIResolver("ProdConection") };

            Kernel = new StandardKernel(modules);
            try
            {
                Kernel.Bind <Func <IKernel> >().ToMethod(ctx => () => new Bootstrapper().Kernel);
                Kernel.Bind <IHttpModule>().To <HttpApplicationInitializationHttpModule>();

                RegisterServices(Kernel);
                GlobalConfiguration.Configuration.DependencyResolver = new NinjectResolver(Kernel); // Resolver DI -  WebApiContrib.IoC.Ninject/ Ninject.Web.WebApi
                return(Kernel);
            }
            catch
            {
                Kernel.Dispose();
                throw;
            }
        }
示例#52
0
        /// <summary>
        /// Creates the kernel that will manage your application.
        /// </summary>
        /// <returns>The created kernel.</returns>
        private static IKernel CreateKernel()
        {
            // устанавливаем строку подключения
            var modules = new INinjectModule[] { new ServiceModule("BlogContext") };
            var kernel  = new StandardKernel(modules);

            try
            {
                kernel.Bind <Func <IKernel> >().ToMethod(ctx => () => new Bootstrapper().Kernel);
                kernel.Bind <IHttpModule>().To <HttpApplicationInitializationHttpModule>();

                RegisterServices(kernel);
                return(kernel);
            }
            catch
            {
                kernel.Dispose();
                throw;
            }
        }
示例#53
0
    public static IKernel GetNewKernel(INinjectModule[] modules)
    {
        var mods = new INinjectModule[] {
            new UnityModule(),
            new LateBoundModule(),
        };

        var allModules = new List <INinjectModule> (mods);

        allModules.AddRange(modules);

        var k = new StandardKernel(new UnityNinjectSettings(), allModules.ToArray());

//		GameObject listener = new GameObject();
//		UnityEngine.Object.DontDestroyOnLoad(listener);
//		listener.name = "LevelLoadListener";
//		listener.AddComponent<LevelLoadListener>();

        return(k);
    }
示例#54
0
        public void TestMemory()
        {
            var modules = new INinjectModule[]
            {
                new TestModule(),
            };

            _kernel = new StandardKernel();
            _kernel.Components.Add<IActivationStrategy, MyMonitorActivationStrategy>();

            _kernel.Load(modules);

            var factory = _kernel.Get<IRootFactory<SomeMainModule>>();
            for (int i = 0;  i < 10000;  i++)
            {
                IObjectRoot<SomeMainModule> someMainModule = factory.Create();
                someMainModule.Get.CreateSub();
                var s = someMainModule as ObjectRoot<SomeMainModule>;
             //   s.Kernel.Dispose();
            }
        }
        private static IKernel CreateKernel()
        {
            var modules = new INinjectModule[] { new ServiceModule("Context", "SyncContext") };
            var kernel  = new StandardKernel(modules);

            try
            {
                kernel.Bind <Func <IKernel> >().ToMethod(ctx => () => new Bootstrapper().Kernel);
                kernel.Bind <IHttpModule>().To <HttpApplicationInitializationHttpModule>();
                RegisterServices(kernel);
                //Hangfire init
                GlobalConfiguration.Configuration.UseNinjectActivator(kernel);
                HangfireAspNet.Use(GetHangfireServers);
                return(kernel);
            }
            catch
            {
                kernel.Dispose();
                throw;
            }
        }
示例#56
0
        /// <summary>
        /// Creates the kernel that will manage your application.
        /// </summary>
        /// <returns>The created kernel.</returns>
        private static IKernel CreateKernel()
        {
            INinjectModule[] configModules = new INinjectModule[] { new IoCConfigModule() };
            AppConfig.InitIoC(configModules);

            var kernel = DependencyManager.Instance().GetKernel();

            try
            {
                kernel.Bind <Func <IKernel> >().ToMethod(ctx => () => new Bootstrapper().Kernel);
                kernel.Bind <IHttpModule>().To <HttpApplicationInitializationHttpModule>();

                RegisterServices(kernel);
                return(kernel);
            }
            catch
            {
                kernel.Dispose();
                throw;
            }
        }
示例#57
0
        public void TestMemory()
        {
            var modules = new INinjectModule[]
            {
                new TestModule(),
            };

            _kernel = new StandardKernel();
            _kernel.Components.Add <IActivationStrategy, MyMonitorActivationStrategy>();

            _kernel.Load(modules);

            var factory = _kernel.Get <IRootFactory <SomeMainModule> >();

            for (int i = 0; i < 10000; i++)
            {
                IObjectRoot <SomeMainModule> someMainModule = factory.Create();
                someMainModule.Get.CreateSub();
                var s = someMainModule as ObjectRoot <SomeMainModule>;
                //   s.Kernel.Dispose();
            }
        }
示例#58
0
        /// <summary>
        /// Creates the kernel that will manage your application.
        /// </summary>
        /// <returns>The created kernel.</returns>
        private static IKernel CreateKernel()
        {
            // в проекте BLL также был создан модуль, который сопоставлял IUnitOfWork с EFUnitOfWork и передавал им название подключения.
            // устанавливаем строку подключения: DefaultConnection
            //
            var modules = new INinjectModule[] { new ServiceModule("DefaultConnection") };
            var kernel  = new StandardKernel(modules);

            try
            {
                kernel.Bind <Func <IKernel> >().ToMethod(ctx => () => new Bootstrapper().Kernel);
                kernel.Bind <IHttpModule>().To <HttpApplicationInitializationHttpModule>();

                RegisterServices(kernel);
                return(kernel);
            }
            catch
            {
                kernel.Dispose();
                throw;
            }
        }
        /// <summary>
        /// Creates the kernel that will manage your application.
        /// </summary>
        /// <returns>The created kernel.</returns>
        private static IKernel CreateKernel()
        {
            var modules = new INinjectModule[] { new ServiceModule("defaultConnection") };
            var kernel  = new StandardKernel(modules);

            try
            {
                kernel.Bind <Func <IKernel> >().ToMethod(ctx => () => new Bootstrapper().Kernel);
                kernel.Bind <IHttpModule>().To <HttpApplicationInitializationHttpModule>();

                var httpResolver = new WebAPIDependencyResolver(kernel);
                System.Web.Http.GlobalConfiguration.Configuration.DependencyResolver = httpResolver;

                RegisterServices(kernel);
                return(kernel);
            }
            catch
            {
                kernel.Dispose();
                throw;
            }
        }
示例#60
0
 public void Load(INinjectModule module)
 {
     Kernel.Root.Load(new[] {module});
 }