ninject

Help with Ninject in mvc3!

北城余情 提交于 2019-12-08 05:45:17
问题 Heres my problem. My app has several projects. WEB (Controllers and views) Services Data (edmx and Repositories) Entities (POCO) Tests So in my Web project I have the ninject configuration [assembly: WebActivator.PreApplicationStartMethod(typeof(PublicPanama.AppStart_NinjectMVC3), "Start")] namespace Web{ public static class AppStart_NinjectMVC3 { public static void RegisterServices(IKernel kernel) { //kernel.Bind<IThingRepository>().To<SqlThingRepository>(); kernel.Bind<IContributorService>(

DbContext with Ninject ADO.NET

本小妞迷上赌 提交于 2019-12-08 05:44:03
问题 I am working on a big project that 80% completed (Some features need to be implemented though).But recently we discovered that the project doesn't allow concurrent requests (I mean multiple users request to same repository). Sometime we get null referece & sometimes "Executed can not open available connection , connection state is closed" etc. Our source code is strongly restricted outside of the world. Here is some code.Let me know if there is any architectural problem, as architectural guys

Inheriting a base controller with constructor

喜你入骨 提交于 2019-12-08 05:11:15
问题 I am using ninject to inject my repositories. I would like to have a my base class to be inherited but I cant because it has a constructor. Base Controller: namespace Orcha.Web.Controllers { public class BaseController : Controller { public IRepository<string> db; public BaseController(Repository<string> db){ this.db = db; Debug.WriteLine("Repository True"); } } } Controller with inherit: Error 'BaseController' does not contain a constructor that takes 0 arguments HomeController.cs public

“Multiple bindings” error when calling ninject2.Get<ConcreteClass>()

ぐ巨炮叔叔 提交于 2019-12-08 04:18:20
问题 I'd like to do something like this: ConcreteClass foo = ninject2.Get<ConcreteClass>( new ConstructorArgument("bar", "qux")); ninject2.Bind<ConcreteClass>().ToConstant(foo); ... ConcreteClass foo = ninject2.Get<ConcreteClass>(); // fail! When I try, I get the error Error activating ConcreteClass. More than one matching bindings are available. What is happening here? 回答1: OOTB, Ninject (esp. v2 - in v1, it was an optional setting that defaulted to on) internally generates implicit bindings for

Ninject WhenInjectedInto equivalent in Simple Injector

佐手、 提交于 2019-12-08 04:09:17
问题 Mapping to constant value. This happens for example when you need to resolve an automapper IMapper instance, Example in Ninject would be var config = new MapperConfiguration( cfg => { cfg.AddProfile( new MyMapperConfiguration() ); } ); Bind<MapperConfiguration>().ToConstant( config ).InSingletonScope(); Bind<IMapper>().ToConstant( config.CreateMapper() ); Bind different implementation based on the injecting type This happens when a set of common classes depends on a common interface but the

In asp.net-mvc, is there a more elegant way using IOC to inject mutiple repositories into a controller?

爱⌒轻易说出口 提交于 2019-12-08 04:06:07
问题 I have an asp.net-mvc website and i am using ninject for IOC and nhibernate for my ORM mapping Here is my IOC binding code: internal class ServiceModule : NinjectModule { public override void Load() { Bind(typeof(IIntKeyedRepository<>)).To(typeof(Repository<>)).InRequestScope(); } } and here is an example of how I am doing IOC into my controller code: public FAQController(IIntKeyedRepository<FAQ> faqRepository, IUnitOfWork unitOfWork) { _faqRepository = faqRepository; _unitOfWork = unitOfWork

Ninject: How to access root object of NamedScope from factory

試著忘記壹切 提交于 2019-12-08 00:10:46
问题 In my application I am using Ninject and the NamedScopeExtension. One of the objects deeper in the object graph needs access to the root object that defined the named scope. It seems to me that DefinesNamedScope() does not also imply InNamedScope() and instead a new root object is created when I request the root. Example: using System; using Ninject; using Ninject.Extensions.NamedScope; using Ninject.Syntax; namespace NInjectNamedScope { public interface IScopeRoot { Guid Guid { get; } void

Erro on Ninject: Sequence contains no elements

微笑、不失礼 提交于 2019-12-07 23:15:20
问题 This error appear just when I publish on Azure server: Sequence contains no elements I'm not sure this error is because of Ninject. I've tried all the tips with similar errors, but it seems that is a generic error. I tried to run the same code on several machines and this error does not happen only when the public Azure. If you have gone through something and can help, thank you very much. Stack Trace : [InvalidOperationException: Sequence contains no elements] System.Linq.Enumerable.Single

Accessing Ninject Kernel.Get() from HttpHandler with existing custom base

对着背影说爱祢 提交于 2019-12-07 22:44:33
问题 I have an ASP.Net webforms app, that uses Ninject 2.2.0.0 I have a HTTPHandler that inherits from the Microsoft.Web.ImageHandler class. Within it i need to access an instance of a service class that i created. because i cannot inherit from Ninject.Web.HttpHandlerBase i thought i would just expose the Kernel as a property on the Global.asax class... protected override IKernel CreateKernel() { IKernel kernel = new StandardKernel(new DefaultModule()); var sms = kernel.Get<SiteMapService>();

NInject Extension Factory

我是研究僧i 提交于 2019-12-07 22:42:55
问题 After reading the new documentation on NInject v3 and how to use the Factory Extension , apparently I still don't get it fully since my code throws exceptions all over the place... I get this Exception, i could paste the whole thing if people would like that but i'll try and keep it short for now. Error activating IDeployEntityContainer No matching bindings are available, and the type is not self-bindable. Here is my code... The Ninject Bind Module class class MyNinjectModule : NinjectModule