ninject

Questions about using Ninject

生来就可爱ヽ(ⅴ<●) 提交于 2019-11-26 05:19:04
I went through the recommended steps to add Ninject to my MVC application. And I added a DbContext argument to my controllers' constructors. Controller: public class MyController : BaseController { public ArticlesController(MyDbContext context) : base(context) { } } Base Controller: public class BaseController : Controller { protected DbContext MyDbContext; public BaseController(MyDbContext context) { MyDbContext = context; } } This seems to work well. But leaves me with a few questions. Does Ninject ensure my DbContext is cleaned up and disposed in a timely fashion? I have created a base

Creating an instance using Ninject with additional parameters in the constructor

…衆ロ難τιáo~ 提交于 2019-11-26 04:12:23
问题 I decided to start using Ninject and face an issue. Say I have the following scenario. I have an IService interface and 2 classes implementing this interface. And also I have a class, which has a constructor getting IService and an int . How can I create an instance of this class with Ninject (I dont want to hardwire this int, I want to pass it every time I get an instance)? Here\'s some code illustrating the situation: interface IService { void Func(); } class StandardService : IService {

Validation: How to inject A Model State wrapper with Ninject?

十年热恋 提交于 2019-11-26 04:08:35
问题 I was looking at this tutorial http://asp-umb.neudesic.com/mvc/tutorials/validating-with-a-service-layer--cs on how to wrap my validation data around a wrapper. I would like to use dependency inject though. I am using ninject 2.0 namespace MvcApplication1.Models { public interface IValidationDictionary { void AddError(string key, string errorMessage); bool IsValid { get; } } } // wrapper using System.Web.Mvc; namespace MvcApplication1.Models { public class ModelStateWrapper :

Dependency Injection with Ninject and Filter attribute for asp.net mvc

荒凉一梦 提交于 2019-11-26 04:08:07
问题 I\'m writing a custom Authorization Filter for asp.net mvc 3. I need to inject a userservice into the class but I have no idea how to do this. public class AuthorizeAttribute : FilterAttribute, IAuthorizationFilter { private IUserService userService; private string[] roles; public AuthorizeAttribute(params string[] roles) { this.roles = roles; } public void OnAuthorization(AuthorizationContext filterContext) { throw new NotImplementedException(); } } I\'m using ninject for dependency

How can I implement Ninject or DI on asp.net Web Forms?

荒凉一梦 提交于 2019-11-26 02:51:08
问题 There are plenty of examples for having it worked on an MVC application. How is it done on Web Forms? 回答1: Here are the steps to use Ninject with WebForms. Step1 - Downloads There are two downloads required - Ninject-2.0.0.0-release-net-3.5 and the WebForm extensions Ninject.Web_1.0.0.0_With.log4net (there is an NLog alternative). The following files need to be referenced in the web application: Ninject.dll, Ninject.Web.dll, Ninject.Extensions.Logging.dll and Ninject.Extensions.Logging

Where should I do Injection with Ninject 2+ (and how do I arrange my Modules?)

偶尔善良 提交于 2019-11-26 01:58:45
问题 I have a solution with two relevant (to this question) projects, and a few others; Class library with functionality used by several other projects. ASP.NET MVC application. My question is basically where I should do IoC with Ninject 2, considering... The class library needs some DI love, among other things in the repository classes which need web request specific session objects (think Unit of Work). The MVC app needs DI since with Ninject 2 you basically inherit from NinjectHttpApplication.

Questions about using Ninject

老子叫甜甜 提交于 2019-11-26 01:54:25
问题 I went through the recommended steps to add Ninject to my MVC application. And I added a DbContext argument to my controllers\' constructors. Controller: public class MyController : BaseController { public ArticlesController(MyDbContext context) : base(context) { } } Base Controller: public class BaseController : Controller { protected DbContext MyDbContext; public BaseController(MyDbContext context) { MyDbContext = context; } } This seems to work well. But leaves me with a few questions.

How do the major C# DI/IoC frameworks compare? [closed]

杀马特。学长 韩版系。学妹 提交于 2019-11-26 00:56:23
问题 At the risk of stepping into holy war territory, What are the strengths and weaknesses of these popular DI/IoC frameworks, and could one easily be considered the best? ..: Ninject Unity Castle.Windsor Autofac StructureMap Are there any other DI/IoC Frameworks for C# that I haven\'t listed here? In context of my use case, I\'m building a client WPF app, and a WCF/SQL services infrastructure, ease of use (especially in terms of clear and concise syntax), consistent documentation, good community

How do the major C# DI/IoC frameworks compare? [closed]

天涯浪子 提交于 2019-11-25 20:04:11
At the risk of stepping into holy war territory, What are the strengths and weaknesses of these popular DI/IoC frameworks, and could one easily be considered the best? ..: Ninject Unity Castle.Windsor Autofac StructureMap Are there any other DI/IoC Frameworks for C# that I haven't listed here? In context of my use case, I'm building a client WPF app, and a WCF/SQL services infrastructure, ease of use (especially in terms of clear and concise syntax), consistent documentation, good community support and performance are all important factors in my choice. Update: The resources and duplicate