当前位置: 首页>>代码示例>>C#>>正文


C# IKernel.Inject方法代码示例

本文整理汇总了C#中IKernel.Inject方法的典型用法代码示例。如果您正苦于以下问题:C# IKernel.Inject方法的具体用法?C# IKernel.Inject怎么用?C# IKernel.Inject使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在IKernel的用法示例。


在下文中一共展示了IKernel.Inject方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Application_Start

        /// <summary>
        /// Starts the application.
        /// </summary>
        public void Application_Start()
        {
            lock (this)
            {
                kernel = this.CreateKernel();

                kernel.Components.RemoveAll<IMissingBindingResolver>();
                kernel.Components.Add<IMissingBindingResolver, ControllerMissingBindingResolver>();
                kernel.Components.Add<IMissingBindingResolver, SelfBindingResolver>();

                kernel.Bind<RouteCollection>().ToConstant(RouteTable.Routes);
                kernel.Bind<HttpContext>().ToMethod(ctx => HttpContext.Current).InTransientScope();
                kernel.Bind<HttpContextBase>().ToMethod(ctx => new HttpContextWrapper(HttpContext.Current)).InTransientScope();
                kernel.Bind<IFilterInjector>().To<FilterInjector>().InSingletonScope();
                
                ControllerBuilder.Current.SetControllerFactory(this.CreateControllerFactory());

                kernel.Inject(this);

                if (kernel.Settings.Get("ReleaseScopeAtRequestEnd", true))
                {
                    OnePerRequestModule.StartManaging(kernel);
                }

                this.OnApplicationStarted();
            }
        }
开发者ID:nectide,项目名称:ninject.web.mvc,代码行数:30,代码来源:NinjectHttpApplication.cs

示例2: Application_Start

        /// <summary>
        /// Starts the application.
        /// </summary>
        public void Application_Start()
        {
            lock (this)
            {
                kernel = this.CreateKernel();

                kernel.Bind<IResolutionRoot>().ToConstant(kernel);
                kernel.Bind<IDependencyResolver>().To<NinjectDependencyResolver>();
                kernel.Bind<IFilterProvider>().To<NinjectFilterAttributeFilterProvider>();
                kernel.Bind<IFilterProvider>().To<NinjectFilterProvider>();
                kernel.Bind<RouteCollection>().ToConstant(RouteTable.Routes);
                kernel.Bind<HttpContext>().ToMethod(ctx => HttpContext.Current).InTransientScope();
                kernel.Bind<HttpContextBase>().ToMethod(ctx => new HttpContextWrapper(HttpContext.Current)).InTransientScope();
                kernel.Bind<ModelValidatorProvider>().To<NinjectDataAnnotationsModelValidatorProvider>();

                ModelValidatorProviders.Providers.Remove(ModelValidatorProviders.Providers.OfType<DataAnnotationsModelValidatorProvider>().Single());
                DependencyResolver.SetResolver(this.CreateDependencyResolver());
                RemoveDefaultAttributeFilterProvider();

                kernel.Inject(this);

                if (kernel.Settings.Get("ReleaseScopeAtRequestEnd", true))
                {
                    OnePerRequestModule.StartManaging(kernel);
                }

                this.OnApplicationStarted();
            }
        }
开发者ID:nectide,项目名称:ninject.web.mvc,代码行数:32,代码来源:NinjectHttpApplication.cs

示例3: Initialize

        /// <summary>
        /// Starts the application.
        /// </summary>
        /// <param name="createKernelCallback">The create kernel callback function.</param>
        public void Initialize(Func<IKernel> createKernelCallback)
        {
            kernelInstance = createKernelCallback();

            kernelInstance.Components.GetAll<INinjectHttpApplicationPlugin>().Map(c => c.Start());
            kernelInstance.Bind<IHttpModule>().To<HttpApplicationInitializationHttpModule>();
            kernelInstance.Inject(this);
        }
开发者ID:Nicholi,项目名称:Ninject.Web.Common,代码行数:12,代码来源:Bootstrapper.cs

示例4: TestAssistant

        public TestAssistant()
        {
            _container = new StandardKernel();

            IoC.GetInstance = (service, key) => _container.Get(service, key);
            IoC.GetAllInstances = (service) => _container.GetAll(service);
            IoC.BuildUp = (instance) => _container.Inject(instance);

            BindConfigs();
        }
开发者ID:Geminior,项目名称:DeepConfig,代码行数:10,代码来源:TestAssistant.cs

示例5: Application_Start

		/// <summary>
		/// Starts the application.
		/// </summary>
		public void Application_Start()
		{
			lock (this)
			{
				_kernel = CreateKernel();

				_kernel.Bind<RouteCollection>().ToConstant(RouteTable.Routes);
				_kernel.Bind<HttpContext>().ToMethod(ctx => HttpContext.Current).InRequestScope();
				_kernel.Bind<HttpContextBase>().ToMethod(ctx => new HttpContextWrapper(HttpContext.Current)).InRequestScope();
				
				ControllerBuilder.Current.SetControllerFactory(new NinjectControllerFactory(_kernel));

				_kernel.Inject(this);

				OnApplicationStarted();
			}
		}
开发者ID:rhhathie,项目名称:ninject.web.mvc,代码行数:20,代码来源:NinjectHttpApplication.cs

示例6: Application_Start

        /// <summary>
		/// Starts the application.
		/// </summary>
		public void Application_Start()
		{
			lock (this)
			{
				_kernel = CreateKernel();

				_kernel.Bind<RouteCollection>().ToConstant(RouteTable.Routes);
                _kernel.Bind<HttpContext>().ToMethod(ctx => HttpContext.Current).InTransientScope();
                _kernel.Bind<HttpContextBase>().ToMethod(ctx => new HttpContextWrapper(HttpContext.Current)).InTransientScope();

                ControllerBuilder.Current.SetControllerFactory(CreateControllerFactory());

				_kernel.Inject(this);

                if (_kernel.Settings.Get("ReleaseScopeAtRequestEnd", true))
                {
                    OnePerRequestModule.StartManaging(_kernel);
                }
                
                OnApplicationStarted();
			}
		}
开发者ID:nectide,项目名称:ninject.web.mvc,代码行数:25,代码来源:NinjectHttpApplication.cs

示例7: Application_Start

		/// <summary>
		/// Starts the application.
		/// </summary>
		public void Application_Start()
		{
			lock (this)
			{
				_kernel = CreateKernel();

                _kernel.Components.RemoveAll<IMissingBindingResolver>();
                _kernel.Components.Add<IMissingBindingResolver, ControllerMissingBindingResolver>();
                _kernel.Components.Add<IMissingBindingResolver, SelfBindingResolver>();

                _kernel.Bind<RouteCollection>().ToConstant(RouteTable.Routes);
				_kernel.Bind<HttpContext>().ToMethod(ctx => HttpContext.Current).InTransientScope();
                _kernel.Bind<HttpContextBase>().ToMethod(ctx => new HttpContextWrapper(HttpContext.Current)).InTransientScope();
			    _kernel.Bind<IFilterInjector>().To<FilterInjector>().InSingletonScope();
				
				ControllerBuilder.Current.SetControllerFactory(CreateControllerFactory());

				_kernel.Inject(this);

				OnApplicationStarted();
			}
		}
开发者ID:Burr,项目名称:ninject.web.mvc,代码行数:25,代码来源:NinjectHttpApplication.cs

示例8: OnStart

 public sealed override bool OnStart()
 {
     Kernel = CreateKernel();
     Kernel.Inject(this);
     return OnRoleStarted();
 }
开发者ID:jonesm13,项目名称:Jonesmatt.Tools,代码行数:6,代码来源:NinjectRoleEntryPoint.cs

示例9: WebServiceBase

 public WebServiceBase(IKernel kernel)
 {
     if (kernel != null)
         kernel.Inject(this);
 }
开发者ID:jchadwick,项目名称:developer-achievements,代码行数:5,代码来源:WebServiceBase.cs

示例10: RegisterServices

        /// <summary>
        /// Load your modules or register your services here!
        /// </summary>
        /// <param name="kernel">The kernel.</param>
        private static void RegisterServices(IKernel kernel)
        {
            // http://stackoverflow.com/questions/9693957/ninject-web-common-throwing-activationexception-trying-to-inject-dependencies-in
            kernel.Bind<Func<IKernel>>().ToMethod(ctx => () => new Bootstrapper().Kernel);
            kernel.Bind<IHttpModule>().To<HttpApplicationInitializationHttpModule>();

            // NHibernate session factory
            kernel.Bind<ISessionFactory>().ToProvider<NHibernateSessionFactoryProvider>().InSingletonScope();
            kernel.Bind<ISession>().ToMethod(context => context.Kernel.Get<ISessionFactory>().OpenSession()).InRequestScope();
            kernel.Bind<IIntegrityServiceManager>().To<IntegrityServiceManager>().InRequestScope();
            kernel.Bind<IUnitOfWorkManager>().To<UnitOfWorkManager>().InRequestScope();

            // Bind the various domain model services and repositories that e.g. our controllers require         
            kernel.Bind<IRoleService>().To<RoleService>().InRequestScope();
            kernel.Bind<ICategoryService>().To<CategoryService>().InRequestScope();
            kernel.Bind<IMembershipService>().To<MembershipService>().InRequestScope();
            kernel.Bind<IPermissionService>().To<PermissionService>().InRequestScope();
            kernel.Bind<ISettingsService>().To<SettingsService>().InRequestScope();
            kernel.Bind<ITopicService>().To<TopicService>().InRequestScope();
            kernel.Bind<ITopicTagService>().To<TopicTagService>().InRequestScope();
            kernel.Bind<IPostService>().To<PostService>().InRequestScope();
            kernel.Bind<ILocalizationService>().To<LocalizationService>().InRequestScope();
            kernel.Bind<IVoteService>().To<VoteService>().InRequestScope();
            kernel.Bind<IBadgeService>().To<BadgeService>().InRequestScope();
            kernel.Bind<IMembershipUserPointsService>().To<MembershipUserPointsService>().InRequestScope();
            kernel.Bind<ICategoryPermissionForRoleService>().To<CategoryPermissionForRoleService>().InRequestScope();
            kernel.Bind<ICategoryNotificationService>().To<CategoryNotificationService>().InRequestScope();
            kernel.Bind<ITopicNotificationService>().To<TopicNotificationService>().InRequestScope();
            kernel.Bind<IPrivateMessageService>().To<PrivateMessageService>().InRequestScope();
            kernel.Bind<ILoggingService>().To<LoggingService>().InRequestScope();
            kernel.Bind<IEmailService>().To<EmailService>().InRequestScope();
            kernel.Bind<IReportService>().To<ReportService>().InRequestScope();
            kernel.Bind<IActivityService>().To<ActivityService>().InRequestScope();

            kernel.Bind<IRoleRepository>().To<RoleRepository>().InRequestScope();
            kernel.Bind<ICategoryRepository>().To<CategoryRepository>().InRequestScope();
            kernel.Bind<IMembershipRepository>().To<MembershipRepository>().InRequestScope();
            kernel.Bind<IPermissionRepository>().To<PermissionRepository>().InRequestScope();
            kernel.Bind<ISettingsRepository>().To<SettingsRepository>().InRequestScope();
            kernel.Bind<ITopicRepository>().To<TopicRepository>().InRequestScope();
            kernel.Bind<ITopicTagRepository>().To<TopicTagRepository>().InRequestScope();
            kernel.Bind<IPostRepository>().To<PostRepository>().InRequestScope();
            kernel.Bind<ILocalizationRepository>().To<LocalizationRepository>().InRequestScope();
            kernel.Bind<IVoteRepository>().To<VoteRepository>().InRequestScope();
            kernel.Bind<IBadgeRepository>().To<BadgeRepository>().InRequestScope();
            kernel.Bind<IMembershipUserPointsRepository>().To<MembershipUserPointsRepository>().InRequestScope();
            kernel.Bind<ICategoryPermissionForRoleRepository>().To<CategoryPermissionForRoleRepository>().InRequestScope();                        
            kernel.Bind<ICategoryNotificationRepository>().To<CategoryNotificationRepository>().InRequestScope();                                   
            kernel.Bind<ITopicNotificationRepository>().To<TopicNotificationRepository>().InRequestScope();
            kernel.Bind<IPrivateMessageRepository>().To<PrivateMessageRepository>().InRequestScope();
            kernel.Bind<IActivityRepository>().To<ActivityRepository>().InRequestScope();

            kernel.Bind<IMVCForumAPI>().To<MVCForumAPI>().InRequestScope();
            kernel.Bind<IPostAPI>().To<PostAPI>().InRequestScope();
            kernel.Bind<ITopicAPI>().To<TopicAPI>().InRequestScope();

            kernel.Bind<ICacheHelper>().To<CacheHelper>().InRequestScope();
            kernel.Bind<ISessionHelper>().To<SessionHelper>().InRequestScope();

            // Locate the membership objects defined via web.config and inject thereby setting any properties decorated with [Inject]
            // applying any ninjectified objects already established
            kernel.Inject(System.Web.Security.Membership.Provider);
            kernel.Inject(System.Web.Security.Roles.Provider);

            // Inject the objects passed by caller e.g. ServiceLocator
            foreach(var obj in _objectsToInject)
            {
                if (obj != null)
                {
                    kernel.Inject(obj);
                }
            }
        }
开发者ID:huchao007,项目名称:mvcforum,代码行数:77,代码来源:NinjectMVC3.cs

示例11: CoreBundle

 /// <summary>
 /// Initializes a new instance of the <see cref="CoreBundle" /> class through injection with the provided kernel.
 /// </summary>
 /// <param name="kernel"></param>
 public CoreBundle(IKernel kernel)
 {
     kernel.Inject(this);
 }
开发者ID:Baloons-Pop-4,项目名称:Main,代码行数:8,代码来源:CoreBundle.cs

示例12: ConsoleBundle

 /// <summary>
 /// Initializes a new instance of the <see cref="ConsoleBundle" /> class.
 /// </summary>
 /// <param name="matrix"></param>
 public ConsoleBundle(IKernel kernel)
     : base(kernel)
 {
     kernel.Inject(this.Reader);
 }
开发者ID:Baloons-Pop-4,项目名称:Main,代码行数:9,代码来源:ConsoleBundle.cs

示例13: Context

 /// <summary>
 /// Initializes a new instance of the <see cref="Context" /> class. Uses a Ninject kernel to inject the current instance.
 /// </summary>
 /// <param name="appKernel"></param>
 public Context(IKernel appKernel)
     : this()
 {
     appKernel.Inject(this);
 }
开发者ID:Baloons-Pop-4,项目名称:Main,代码行数:9,代码来源:Context.cs

示例14: WpfBundle

 /// <summary>
 /// Initializes a new instance of the <see cref="WpfBundle" /> class through injection with the provided kernel.
 /// </summary>
 /// <param name="kernel"></param>
 public WpfBundle(IKernel kernel)
     : base(kernel)
 {
     kernel.Inject(this.Gui);
 }
开发者ID:Baloons-Pop-4,项目名称:Main,代码行数:9,代码来源:WpfBundle.cs

示例15: InjectOnKernelExtension

 /// <summary>
 /// Initializes a new instance of the <see cref="InjectOnKernelExtension"/> class.
 /// </summary>
 /// <param name="kernel">The kernel.</param>
 public InjectOnKernelExtension(IKernel kernel)
     : base((a, r) => kernel.Inject(a, new RootActivityParameter(r)))
 {
 }
开发者ID:dmetzgar,项目名称:Ninject.Extensions.Wf,代码行数:8,代码来源:InjectOnKernelExtension.cs


注:本文中的IKernel.Inject方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。