ninject

Does thread scope in ninject creates new dbcontext on every thread call

假如想象 提交于 2019-12-24 11:28:05
问题 I have configured ninject in wep api as below. I have created two kernel objects, one in request scope and another in thread scope: var requestKernel = new StandardKernel(); requestKernel.Bind<IGlobalDbContext>().ToConstructor(ctx => new GlobalDbContext(Configuration.GlobalDbContext)).InRequestScope(); var threadKernel = new StandardKernel(); RegisterServices(threadKernel); threadKernel.Bind<IGlobalDbContext>().ToConstructor(ctx => new GlobalDbContext(Configuration.GlobalDbContext))

Ninject bind mulitple implementations to an interface

旧城冷巷雨未停 提交于 2019-12-24 09:26:19
问题 I'm looking at this tutorial, but not quite understanding how to create a factory that can provide me separate implementations of an interface. http://stefanoricciardi.com/2011/01/21/ninject-mini-tutorial-part-1/ public class IJob { ... } public class JobImpl1 : IJob { ... } public class JobImpl2 : IJob { ... } using (IKernel kernel = new StandardKernel()) { kernel.Bind<IJob>().To<JobImpl2>(); var job = kernel.Get<IJob>(); } My goal is to make a factory class that wraps this Ninject Kernel so

How to inject repositories into a custom MembershipProvider?

ぃ、小莉子 提交于 2019-12-24 08:42:51
问题 It seem i can't get this to work. I made a custom MembershipProvider and i want to inject a repository inside but the [Inject] property just doesnt work. public class PyrosphereMembershipProvider : MembershipProvider { [Inject] protected IDepositoireUtilisateur DepositoireUtilisateur { get; set; } [Inject] protected IDepositoireProfile DepositoireProfile { get; set; } ... I think this is because this class are created way before the MVC application is running which cause the actual problem. I

How to inject repositories into a custom MembershipProvider?

孤者浪人 提交于 2019-12-24 08:40:01
问题 It seem i can't get this to work. I made a custom MembershipProvider and i want to inject a repository inside but the [Inject] property just doesnt work. public class PyrosphereMembershipProvider : MembershipProvider { [Inject] protected IDepositoireUtilisateur DepositoireUtilisateur { get; set; } [Inject] protected IDepositoireProfile DepositoireProfile { get; set; } ... I think this is because this class are created way before the MVC application is running which cause the actual problem. I

Ninject: Shared DI/IoC container

江枫思渺然 提交于 2019-12-24 07:32:10
问题 I want to share the container across various layers in my application. I started creating a static class which initialises the container and register types in the container. public class GeneralDIModule : NinjectModule { public override void Load() { Bind<IDataBroker>().To<DataBroker>().InSingletonScope(); } } public abstract class IoC { private static IKernel _container; public static void Initialize() { _container = new StandardKernel(new GeneralDIModule(), new ViewModelDIModule()); }

An entity object cannot be referenced by multiple instances of IEntityChangeTracker error

与世无争的帅哥 提交于 2019-12-24 07:29:15
问题 I understand there are a lot of duplicates to this question, but I couldn't find one that fits my scenario. So I am using the ASP.NET MVC 4 + Entity Framework + Ninject using repository pattern (I see many mentions of repository + unit of work pattern? That could be a potential fix to my problem but I don't know how to implement it). When I try to add a new post, I get "An entity object cannot be referenced by multiple instances of IEntityChangeTracker" error on the following line of code

Inject custom code in standard application

笑着哭i 提交于 2019-12-24 07:00:12
问题 We have a standard application in our company. Now I want to inject some custom assemblies in the application. Normally if you have a ninject kernel or unity container, you can get the implementation like below: IKernel kernel = new StandardKernel(); DealerService myServ = new DealerService(kernel.Get<IDealerController>()); DealerService: public partial class DealerService : ServiceBase { private readonly IDealerController Controller; public DealerService(IDealerController controller) {

Dependency injection in custom workflow activity

為{幸葍}努か 提交于 2019-12-24 05:28:52
问题 I have a standard application that has a workflow. The customer can customize the workflow in the designer. Now we are making some custom activities for a specific customer. The custom activity is communicating against the business layer by a interface. How do I give the interface an implementation of that interface? It is very important that the standard application doesn't know about the interface and implementation of that interface because it is custom code for that specific customer. The

Ninject error: he IControllerFactory 'Ninject.Web.Mvc.NinjectControllerFactory' did not return a controller for the name 'Products'

僤鯓⒐⒋嵵緔 提交于 2019-12-24 04:02:11
问题 I'm Getting the following yellow screen of death "The IControllerFactory 'Ninject.Web.Mvc.NinjectControllerFactory' did not return a controller for the name 'Products'." Why? Here's my setup Update This configuration works on my computer but not on my co-worker's computer even though our computers have the same code and configuration. Code public class MvcApplication : NinjectHttpApplication { public static void RegisterRoutes(RouteCollection routes) { routes.IgnoreRoute("{resource}.axd/{

Binding Generic Types in Ninject 3.0

空扰寡人 提交于 2019-12-24 02:30:35
问题 I want Ninject to create Bindings for all types within a specific assembly that implement a generic interface, without specifying them all at runtime. Kind of like how open generics work in Autofac. This is what i came up with... kernel.Bind(x => x.FromThisAssembly() .SelectAllClasses() .Where(t => t.IsAssignableFrom( typeof(ICommandHandler<>))) .BindAllInterfaces()); Calling the method below, i would expect an array of all types implementing ICommandHandler<T> but it yields nothing... public