ninject

Intercept creation of instances in Ninject

▼魔方 西西 提交于 2019-12-11 10:16:20
问题 I am looking to intercept the creation of instances that implement a certain interface, or have a certain attribute. I am able to do something similiar with the interception extension, but that only seems to do method and property interception. Here is how I can intercept method and property calls, but it doesn't intercept the constructor call: _kernel.Bind<IInterceptor>().To<LogInterceptor>().InSingletonScope(); _kernel.Intercept(x => { if (x.Plan.Type.GetInterface(typeof

.NET memory profiling / risks for leaks / Ninject / Direct delegate roots

感情迁移 提交于 2019-12-11 08:56:56
问题 I am profiling an application that uses Ninject for DI. Over the course of time, I am seeing lots of instances of the BindingBuilder class, which is used to define the objects defined in the container. Ninject's "ToMethod" binding is used to define all the objects in the container. The context available in the lamba to access the kernel is then used to retrieve other objects from the container. Example: Bind<IService>() .ToMethod(ctx => new CustomService( ctx.Kernel.GetDefault<IOtherService>(

c# .NET MVC 4 - How do I create Quartz jobs that use Ninject services?

六眼飞鱼酱① 提交于 2019-12-11 08:33:50
问题 I am using .NET MVC 4. All services are injected using Ninject. I am trying to schedule a job using Quartz. Right now, jobs are registered in Global.asax as follows: Global.asax : protected void Application_Start() { // ... configuration stuff ScheduledJobs.RegisterJobs(); } ScheduleJobs.cs has the ScheduledJobs class, which creates jobs with triggers and adds them to a standard schedule. In ScheduleJobs.cs : public class ScheduledJobs { public static void RegisterJobs() { IScheduler

ASP.NET MVC and IoC - Chaining Injection

自作多情 提交于 2019-12-11 08:26:16
问题 Please be gentle, I'm a newb to this IoC/MVC thing but I am trying. I understand the value of DI for testing purposes and how IoC resolves dependencies at run-time and have been through several examples that make sense for your standard CRUD operations... I'm starting a new project and cannot come up with a clean way to accomplish user permissions. My website is mostly secured with any pages with functionality (except signup, FAQ, about us, etc) behind a login. I have a custom identity that

Bug in Ninject?

做~自己de王妃 提交于 2019-12-11 08:24:19
问题 Looking for advice on whether I have a real bug or not and if it is, how to fix it best: I have a highly multi-threaded process that runs 24/7. There are a few objects that are injected with bindings provided in ThreadScope by Ninject. As the load on the process has been ever increasing, the process started crashing more and more often. Error message in the event log was this: > Framework Version: v4.0.30319 Description: The process was terminated > due to an unhandled exception. Exception

How to wrap lazy loading in a transaction?

左心房为你撑大大i 提交于 2019-12-11 08:03:26
问题 I am using nhibernate and the nhibernate profile what keeps throwing this alert. Use of implicit transactions is discouraged" I actually wrap everything in a transaction through ninject public class NhibernateModule : NinjectModule { public override void Load() { Bind<ISessionFactory>().ToProvider<NhibernateSessionFactoryProvider>().InSingletonScope(); Bind<ISession>().ToMethod(context => context.Kernel.Get<ISessionFactory>().OpenSession()).InRequestScope() .OnActivation(StartTransaction)

Multiple dbcontexts with Repository, UnitOfWork and Ninject

那年仲夏 提交于 2019-12-11 07:45:16
问题 I am slowly getting to grips with EF, repository, UnitOfWork and Ninject and have included my implementation so far (see below). The purpose of my data layer is to provide the ability to read data from the existing HR system which has an Oracle back end, and provide addition functionality by consuming this data. The application I am building will use a SQL backend, currently I have just created some extra tables in the HR systems Oracle dbm but I want to keep this separate and hook in to

Ninject.Web (webforms extension), injecting outside of a webform page?

梦想的初衷 提交于 2019-12-11 07:33:15
问题 I've been using the Ninject.Web extension to inject business objects, repositories, Entity Framework context etc into my application. This works very well using the [Inject] attribute which can be applied within a webform that inherits from PageBase. I am now running into a snag as I am trying to write a custom membership provider that needs injection done inside of it but of course this provider is not instantiated from within a webform. Forms Authentication will instantiate the object when

Ninject property binding, how to do correctly

别说谁变了你拦得住时间么 提交于 2019-12-11 06:49:20
问题 I have installed Ninject (v4.0.30319) package in test project to test. Create test code below, unfortunately ValidateAbuse.Instance.Repository is always Null. Why Ninject do not bind repository to ValidateAbuse.Repository property? Some of you may suggest to use constructor binding but I can't use it due to code structure. The below code is just example and I need to find a way to bind to property. Test method which always fail [TestMethod] public void PropertyInjection() { using (IKernel

Ninject bind generic interface

﹥>﹥吖頭↗ 提交于 2019-12-11 06:41:24
问题 This is a follow up to Generic Interface dependency injection into factory The answer is correct, but I oversimplified the code. Because with out parameter on the interface you can't have the TOrderRequest as an input parm in the create method. And with Out and In on the interface the binding wont work again. So how do you bind this with Ninject? using System; using Ninject; using System.Collections.Generic; using System.Linq; namespace NinjectPlayGround { class Program { static void Main