public CustomIdentity(FormsAuthenticationTicket ticket)
 {
     _ticket = ticket;
     var kernel = new StandardKernel();
     AccountRepository = new AccountRepository();
     kernel.Inject(AccountRepository);
 }
 public virtual void SetUp()
 {
     NinjectSettings settings = new NinjectSettings()
                                    {
                                        InjectNonPublic = true
                                    };
     IKernel kernel = new StandardKernel(settings, new CoreBindingModule(), new DataAccessBindingModule());
     kernel.Inject(this);
 }
Exemple #3
0
        protected void Application_Start()
        {
            AreaRegistration.RegisterAllAreas();

            RegisterGlobalFilters(GlobalFilters.Filters);
            RegisterRoutes(RouteTable.Routes);
            DependencyResolver.SetResolver(new NinjectDependencyResolver());

            var _kernel = new StandardKernel(new CoreInjectionModule());
            _kernel.Inject(Membership.Provider);
        }
        public void CanResolveDependenciesOnExistingObject()
        {
            var kernel = new StandardKernel();
            kernel.Bind<IWeapon>().To<Lightsaber>();

            var darth = new SithLord();

            darth.Weapon.ShouldBeNull();

            kernel.Inject(darth);

            darth.Weapon.ShouldBeInstanceOf<Lightsaber>();
        }
        public void CanResolveDependenciesOnExistingObject()
        {
            var kernel = new StandardKernel();
            kernel.Bind<IWeapon>().To<Lightsaber>();

            var darth = new SithLord();

            Assert.That(darth.Weapon, Is.Null);

            kernel.Inject(darth);

            Assert.That(darth.Weapon, Is.InstanceOf<Lightsaber>());
        }
        public void Deve_resolver_dependencias_manualmente()
        {
            IKernel kernel = new StandardKernel(new Modulo());

            // A instância normal não tem as dependências resolvidas;
            var servico = new Servico();

            Assert.IsNull(servico.Fornecedor);

            // O método Inject resolve as dependências da instância usando como marcador o atributo [Inject];
            kernel.Inject(servico);

            Assert.IsNotNull(servico.Fornecedor);
            Assert.IsInstanceOfType(servico.Fornecedor, typeof(Fornecedor));
        }
Exemple #7
0
        static void BuildUp()
        {
            Console.Write("Straight:\t");
            watch.Start();
            for(int i = 0; i < n; ++i) {
                var c = new TestClass5();
                c.t = new TestClass1();
            }
            watch.Stop();
            Console.WriteLine(watch.Elapsed);
            watch.Reset();

            Console.Write("pooDI:\t\t");
            watch.Start();
            var pooDI = new DI.Container();
            pooDI.RegisterType<ITestClass1, TestClass1>(false);
            for(int i = 0; i < n; ++i) {
                var c = new TestClass5();
                pooDI.BuildUp<TestClass5>(c);
            }
            watch.Stop();
            Console.WriteLine(watch.Elapsed);
            watch.Reset();

            Console.Write("Unity:\t\t");
            watch.Start();
            var unity = new UnityContainer();
            unity.RegisterType<ITestClass1, TestClass1>();
            for(int i = 0; i < n; ++i) {
                var c = new TestClass5();
                unity.BuildUp<TestClass5>(c);
            }
            watch.Stop();
            Console.WriteLine(watch.Elapsed);
            watch.Reset();

            Console.Write("Ninject:\t");
            watch.Start();
            var kernel = new StandardKernel();
            kernel.Bind<ITestClass1>().To<TestClass1>();
            for(int i = 0; i < n; ++i) {
                var c = new TestClass5();
                kernel.Inject(c);
            }
            watch.Stop();
            Console.WriteLine(watch.Elapsed);
            watch.Reset();

            Console.Write("Autofac:\t");
            watch.Start();
            var builder = new ContainerBuilder();
            builder.RegisterType<TestClass1>().As<ITestClass1>();
            var container = builder.Build();
            for(int i = 0; i < n; ++i) {
                var c = new TestClass5();
                container.InjectProperties<TestClass5>(c);
            }
            watch.Stop();
            Console.WriteLine(watch.Elapsed);
            watch.Reset();

            Console.WriteLine("Castle Windsor:\tNot supported");
        }
Exemple #8
0
 public void Initialize()
 {
     IKernel kernel = new StandardKernel(this.GetInstanceDIControllersModule());
     kernel.Settings.ActivationCacheDisabled = false;
     kernel.Inject(this);
 }
        internal void InitialiseAdapter()
        {
            _logger.Info("Requesting Adapter Start");

            if (PlatformConnector == null)
            {
                _logger.Fatal("Plugin could not be found. Ensure that plugin is copied in folder and restart the service");
                return;
            }

            List<INinjectModule> modules = new List<INinjectModule> { new BootStrapper() };

            if (PluginBootstrapper != null)
            {
                _logger.InfoFormat("Plugin Bootstrapper found of type={0}", PluginBootstrapper.GetType().Name);
                modules.AddRange(PluginBootstrapper.BootstrapModules);
            }

            StandardKernel iocContainer = new StandardKernel(modules.ToArray());


            var settings = iocContainer.Get<ISettings>();
            var service = iocContainer.Get<IServiceFacade>();
            var streamListenerManager = iocContainer.Get<IStreamListenerManager>();
            
            iocContainer.Settings.InjectNonPublic = true;
            
            //needed for Plugin properties since plugin is not instantiated by Ninject
            iocContainer.Inject(PlatformConnector);

            _adapter = new Adapter(settings, service, PlatformConnector, streamListenerManager);

            if (settings.UseSupervisor)
            {
                // SS.Integration.Diagnostics.RestService uses Owin.HttpListeners.
                // that assembly must be referenced in the startup project even if not
                // directly used, so do not remove it from the list of references
                _supervisor = iocContainer.Get<ISupervisor>();
                if (_supervisor == null)
                {
                    _logger.Error("Cannot instantiate Supervisor as not suitable module was found");
                }
                else
                {
                    _logger.Info("Initializing adapter's supervisor");
                    try
                    {
                        _supervisor.Initialise();
                    }
                    catch (Exception e)
                    {
                        _logger.Error("An error occured during the initialization of the adapter's supervisor. The supervisor will not be available", e);
                    }
                }
            }


            _adapter.Start();

            _logger.Info("Adapter has started");
        }
Exemple #10
0
        public BaseApiController()
        {
            var kernel = new Ninject.StandardKernel();

            kernel.Inject(this);
        }