本文整理汇总了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();
}
}
示例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();
}
}
示例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);
}
示例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();
}
示例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();
}
}
示例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();
}
}
示例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();
}
}
示例8: OnStart
public sealed override bool OnStart()
{
Kernel = CreateKernel();
Kernel.Inject(this);
return OnRoleStarted();
}
示例9: WebServiceBase
public WebServiceBase(IKernel kernel)
{
if (kernel != null)
kernel.Inject(this);
}
示例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);
}
}
}
示例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);
}
示例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);
}
示例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);
}
示例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);
}
示例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)))
{
}