ninject

Referencing Ninject in class library in ASP.NET MVC 3 application

半世苍凉 提交于 2019-12-01 18:34:10
I have an ASP.NET MVC 3 application that uses the Ninject.MVC3 extension to setup DI in my MVC application. Namely, there's the NinjectMVC3.cs file in the App_Start folder where my bindings are defined. This works well for DI into my application's controllers. In addition to the ASP.NET MVC web application, my Solution also contains a class library projects, let's call it MyProject.Core , which has my domain model, services, and so on. In there I have a class called UserServices that uses a service called EmailServices , like so: public class UserServices : IUserServices { private readonly

Ninject “No parameterless constructor defined for this object.”

半腔热情 提交于 2019-12-01 18:20:45
I'm testing Ninject, but following the how-to, i find it impossible to make it work. The information on the web is so messy even contradictory. I'm developping a website in MVC 4 on visual studio 2012 and i did install Ninject using Nuget. So I get an error : "No parameterless constructor defined for this object.". As soon as I enter my controller. I did the necessary steps : Nuget installation in NinjectWebCommon.cs, I did register my Interface in the RegisterServices method. In my homecontroller I set my object like this : public ISurvey _survey { get; set; } [Inject] public HomeController

Why won't Ninject resolve protected properties in a base class?

谁说胖子不能爱 提交于 2019-12-01 18:19:26
问题 Simple question I guess, but I've spent an hour trying to get a base class for my controllers to have a few services injected via property injection. The properties were scoped protected at first, but the objects kept coming back null, once I changed the scope to public it worked. Is there anyway to have the properties be protected and get the IoC to work? Here is my setup. public class BaseController : Controller { [Inject] protected LoggingInterface.ILogger<BaseController> Logger { set; get

Can I specify the scope in Ninject for only this specific situation?

 ̄綄美尐妖づ 提交于 2019-12-01 18:11:25
问题 Earlier I asked this question. The answer to which resulted into another question like thou seeth before thee. The initial problem My problem is, that I have a custom MembershipProvider using an AccountRepository using an ObjectContext . Because the MembershipProvider is a Singleton in MVC (as I understand), the AccountRepository and its ObjectContext should be injected once and stay there for the remainder of the MembershipProvider 's life time. However, in my controllers I also use

Why won't Ninject resolve protected properties in a base class?

拥有回忆 提交于 2019-12-01 18:08:13
Simple question I guess, but I've spent an hour trying to get a base class for my controllers to have a few services injected via property injection. The properties were scoped protected at first, but the objects kept coming back null, once I changed the scope to public it worked. Is there anyway to have the properties be protected and get the IoC to work? Here is my setup. public class BaseController : Controller { [Inject] protected LoggingInterface.ILogger<BaseController> Logger { set; get; } [Inject] protected IRepository Repository { set; get; } protected override void OnAuthorization

Ninject 3 InRequestScope not returning the same instance for the same request

青春壹個敷衍的年華 提交于 2019-12-01 16:44:04
Recently, I upgraded one of my MVC3 projects from Ninject 2 to Ninject 3. After a couple of minutes trying to find why InRequestScope was not anymore available, I found that this is now an extension of Ninject.Web.Common. Now, when I try to run the application, Ninject works like if all types binded with a scope InRequest would be InTransientScope; a new instance was created each time. In my class that inherits from NinjectModule, I have a simple bind like that: Bind<ViewModel.Activity>().ToSelf().InRequestScope(); In my controller, I have 2 properties of the type ViewModel.Activity marked

Ninject and static classes - how to?

元气小坏坏 提交于 2019-12-01 16:27:53
I have a static class and I need to inject some instances into it. A static class can have a static constructor but it must be parameterless. So, how am I supposed to injet something into it? I do not wish to create a singleton. I wish to have a static class, and one of its methods operate on an instance that should be injected. Bellow is an example of what I need. public static class AuthenticationHelper { // Fields. private static object _lock = new object(); private static readonly UserBusiness _userBusiness; // <-- this field needs to be injected. // Public properties. public static User

Error loading EntityFramework 4.3.1

ε祈祈猫儿з 提交于 2019-12-01 15:58:39
I created an MVC application in C#. I created a new project in my solution called PhoneDomain. The purpose of this is to separate my data and domain layer from the actual problem. I right clicked on the project and went to "Add Library Package Reference" and I attempted to add the EntityFramework package (version 4.3.1). It said " Operation Failed " " This package contains an init.ps1 file and needs to be installed from the Package Manager Console ". So I opened the Package Manager Console in Visual Studio and typed the following into the console window: install-package EntityFramework

ActionFilterAttribute ninject injection - DbContext has been disposed

会有一股神秘感。 提交于 2019-12-01 15:57:50
问题 I have my project which uses the usual Repository pattern with Services and Unit of Work (all with Ninject injecting the dependencies from a NinjectModule), but I'm trying to access a service from an ActionFilterAttribute to inject some information (from DB) in the layout of the pages I show so I don't need to mess with all the actions on each controller. The problem comes when I save to DB on one screen and move to the next and then come back to the previous (with a standard @Url.Action ):

Automapper exception: “Missing type map configuration or unsupported mapping.”

和自甴很熟 提交于 2019-12-01 15:55:46
I am trying to use Ninject in an ASP.NET MVC 5 application that uses AutoMapper for mapping the Model to the View Model and vice versa. Unfortunately I get an error message that states that the type map configuration is missing. I created a Ninject dependency resolver: namespace MyNamespace.Infrastructure { public class NinjectDependencyResolver: IDependencyResolver { private IKernel kernel; public NinjectDependencyResolver(IKernel kernelParam) { kernel = kernelParam; AddBindings(); } public object GetService(Type serviceType) { return kernel.TryGet(serviceType); } public IEnumerable<object>