ninject

Connection string exception after upgrading to Ninject 3.0.0-rc3

允我心安 提交于 2019-12-02 13:17:07
问题 I recently updated my web site project to Ninject 3.0.0-rc3 and after that I am getting the errors saying "The supplied connection is not valid because it contains insufficient mapping or metadata information." All of this was working when I was using Version 2.2.0.0. Any idea what would have caused this exception to show up and also how can I resolve it? I am using EF and my backend is SQL Server 2008 R2. 回答1: I had the same issue, and I fixed it by switching back to extending

Is this right to inject the container/kernel to the main application presenter? [duplicate]

旧巷老猫 提交于 2019-12-02 12:28:13
This question already has an answer here: Is it better to create a singleton to access unity container or pass it through the application? [closed] 4 answers I'm using Ninject to handle my dependencies. My ApplicationPresenter is responsible to dispatch the user calls to features throughout the application, hence the need to inject multiple factories at once, thus the container itself. It handles an MDI GUI. Is there a better approach? Is it okay to make it so? ApplicationPresenter public class ApplicationPresenter : Presenter<IApplicationView> , IApplicationPresenter { public

No parameterless constructor error in WebJobs with .NET Core and Ninject

孤人 提交于 2019-12-02 11:36:16
I'm trying to do a bit of a balancing act here. Currently Azure WebJobs don't support .NET Core. With some help, I created a .NET Core Console App and made it work as a WebJob. On top of that I'm trying to implement Ninject for DI. Code compiles fine but when I run it, I'm getting the "No parameterless constructor is defined for this object." error -- see below. I may be in a bit of unchartered territory here with Azure WebJobs, .NET Core 2.0 and Ninject but any idea what may be causing this? BTW, I had the same exact code running as a WebJob targeting .NET Framework. I needed to migrate to

Ninject, DbContext & Windows Service - New Instance Each Time Thread Runs?

旧巷老猫 提交于 2019-12-02 11:17:09
I'm current writing a Windows Service which connects to an existing service layer using Entity Framework (DbContext), and Ninject to inject the Respositories and DbContext instance. This is pretty much working with one caveat - I want a brand new DbContext instance each time the thread runs, whereas at the moment I'm getting the same one for the entire thread lifetime. My binding looks like this: Bind<IDbContext>().To<EnterpriseDbContext>().InThreadScope(); Bind<IUserRepository>().To<UserRepository>().InThreadScope(); // And other repositories And my thread code looks like this: [Inject]

Can't get value of Ninject ConstructorArgument (passed in as parameter to kernel.Get)

有些话、适合烂在心里 提交于 2019-12-02 09:48:57
Having trouble getting the value of a ConstructorArgument parameter passed to kernel.Get(). I want to use the parameter's value to determine which of two string values will be passed into the constructor. The parameter is in fact there when expected, I just can't get at its value. I end up with a null ref exception after calling the parameter's GetValue method: namespace MyNS.DBProviders { public abstract class DBProviderBase { private ObjectContext _db; public DBProviderBase(ObjectContext db) { _db = db; } ... //abstract methods here ... } public class DBProviderB : DBProviderBase { public

Ninject and configuration

☆樱花仙子☆ 提交于 2019-12-02 09:01:36
I used to use Castle as an IoC but I had a problem using Nhibernate/Castle(IoC) in the same project so i moved to Ninject. Now to get to the question, I have this class: class CustomModule : NinjectModule { public override void Load() { Bind<Interfaces.ICafe>().To <Concrete.Tea>(); } } Concrete is a separate project and Interfaces.ICafe is a different project. With Castle I used to give a developer the interfaces DLL and ask him to implement a new concrete implementing that interface and then configure that with the app.config, so no matter what class name he implements it still works because

Ninject. Strange intercept to inner set-properties

旧巷老猫 提交于 2019-12-02 08:52:37
Domain object: TargetObject.cs public class TargetObject { public virtual ChildTargetObject ChildTargetObject { get { return ChildTargetObjectInner; } set { ChildTargetObjectInner = value; } } public virtual ChildTargetObject ChildTargetObjectInner { get; set; } } Configuration and test: var settings = new NinjectSettings { InjectNonPublic = true, AllowNullInjection = true }; var kernel = new StandardKernel(settings); kernel.Bind<TargetObject>().ToSelf(); kernel.InterceptReplaceSet<TargetObject>(t => t.ChildTargetObjectInner, (inv) => { inv.Proceed(); // <= we never step here. Why? } ); var o

C# - Ninject, IoC and factory pattern

有些话、适合烂在心里 提交于 2019-12-02 07:27:37
问题 I have a console application where I need to execute a certain feature based on input from the user. If the user puts in "feature 1" -> I execute Feature 1, and so on. I am trying to write this project as clean and as generic as possible, and I want to use the IoC and SOLID concepts, and i am kinda stuck. What I have so far: public interface IFeature { String execFeature(); } and interface IFeatureFactory { IFeature createFeature(String input); } My first thought was just to have a switch

Connection string exception after upgrading to Ninject 3.0.0-rc3

为君一笑 提交于 2019-12-02 07:23:38
I recently updated my web site project to Ninject 3.0.0-rc3 and after that I am getting the errors saying "The supplied connection is not valid because it contains insufficient mapping or metadata information." All of this was working when I was using Version 2.2.0.0. Any idea what would have caused this exception to show up and also how can I resolve it? I am using EF and my backend is SQL Server 2008 R2. I had the same issue, and I fixed it by switching back to extending NinjectHttpApplication rather than the NinjectWebCommon.cs approach. See https://github.com/ninject/ninject.web.mvc/wiki

Ninject: entity object cannot be referenced by multiple instances of IEntityChangeTracker

我只是一个虾纸丫 提交于 2019-12-02 07:21:20
I am starting to use Ninject in my MVC5 code-first app. Here's my NinjectWebCommon.cs: private static IKernel CreateKernel() { var kernel = new StandardKernel(); try { kernel.Bind<Func<IKernel>>().ToMethod(ctx => () => new Bootstrapper().Kernel); kernel.Bind<IHttpModule>().To<HttpApplicationInitializationHttpModule>(); kernel.Bind<CMSContext>() .ToSelf() //.InSingletonScope(); .InRequestScope(); kernel.Bind<IExecutiveRepository>() .To<ExecutiveRepository>(); kernel.Bind<IExecutiveSectionRepository>() .To<ExecutiveSectionRepository>(); kernel.Bind<IExecutiveSectionMappingRepository>() .To