ninject

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

心不动则不痛 提交于 2019-11-26 14:59:12
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 : IValidationDictionary { private ModelStateDictionary _modelState; public ModelStateWrapper(ModelStateDictionary

Guidelines For Dispose() and Ninject

邮差的信 提交于 2019-11-26 14:26:23
问题 So, I have a method exposed from a WCF service as such: public GetAllCommentsResponse GetAllComments(GetAllCommentsRequest request) { var response = new GetAllCommentsResponse(); using(_unitOfWork) try { Guard.ArgNotNull(request, "request"); var results = _unitOfWork.CommentRepository.Get(d => d.Id > 0).ToArray(); //... Do rest of stuff here } catch (Exception ex) { response.Success = false; response.FailureInformation = ex.Message; Logger.LogError("GetAllComments Method Failed", ex); }

Using Dependency Injection without any DI Library

女生的网名这么多〃 提交于 2019-11-26 14:09:43
问题 I am new to Repository and DI and trying to implement in my MVC 5 project. I implemented Constructor Injection where in my controller has a constructor like this: IBook _ibook; public Test(IBook ibook) { _ibook = ibook; } Without any DI library, it throws an error: There is no empty constructor. To avoid this, I added one more constructor as below: public Test ():this(new Book()) { } Since I am new to DI, I don't want to risk my project by using DI library which can later throw some error

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

旧时模样 提交于 2019-11-26 12:48:43
There are plenty of examples for having it worked on an MVC application. How is it done on Web Forms? 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.Log4net.dll. Step 2 - Global.asax The Global class needs to derive from Ninject.Web.NinjectHttpApplication and

How to handle DBContext when using Ninject

青春壹個敷衍的年華 提交于 2019-11-26 11:09:32
问题 I am trying to use Ninject and OpenAccess for the first time. Please help me with the following. Here is what my project looks like... public class ContentController : Controller { private ContentService contentSvc; public ContentController(ContentService contentSvc) { this.contentSvc = contentSvc; } } The following class is under a folder in my web app. public class ContentService { private IContentRepository contentRepository; public ContentService(IContentRepository contentRepository) {

MVC5, Web API 2 and Ninject

依然范特西╮ 提交于 2019-11-26 08:49:37
问题 I have created a new MVC5 project with Web API 2, I then added the Ninject.MVC3 package from NuGet. Constructor injection is working fine for the MVC5 controllers, but i am getting an error when trying to use it with the Web API Controllers. An error occurred when trying to create a controller of type \'UserProfileController\'. Make sure that the controller has a parameterless public constructor. Constructor for working MVC5 controller: public class HomeController : Controller { private

Looking for a Ninject scope that behaves like InRequestScope

二次信任 提交于 2019-11-26 08:37:19
问题 On my service layer I have injected an UnitOfWork and 2 repositories in the constructor. The Unit of Work and repository have an instance of a DbContext I want to share between the two of them. How can I do that with Ninject ? Which scope should be considered ? I am not in a web application so I can\'t use InRequestScope . I try to do something similar... and I am using DI however, I need my UoW to be Dispose d and created like this. using (IUnitOfWork uow = new UnitOfWorkFactory.Create()) {

Continued Ninject support in ASP.NET MVC 6?

…衆ロ難τιáo~ 提交于 2019-11-26 08:33:56
问题 I have been very happily using Ninject for a long time now, and I really like it, but I am faced with a difficult choice since the release of ASP.NET 5 and MVC 6 . Basically, out of the gate, Microsoft has revealed their own dependency injection system; Which is one that to my knowledge has gotten a lot of criticism. But my bigger problem lies with how it affects other libraries. From another question I asked and other resources online, it seems that Ninject does not work out of the box with

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

心已入冬 提交于 2019-11-26 07:51:41
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. Unit tests for the class library need to be aware of this to inject a different set of repositories.

Does Ninject support Func (auto generated factory)?

允我心安 提交于 2019-11-26 05:29:55
问题 Autofac automatically generates factories for Func<T> ; I can even pass parameters. public class MyClass { public MyClass(Func<A> a, Func<int, B> b) { var _a = a(); var _b = b(1); } } Can I do the same with Ninject? If not, what workaround can I apply? Thanks. Update : Just found this post, seems the answer is no: How do I handle classes with static methods with Ninject? 回答1: NB Ninject 3.0 and later has this fully supported using the Ninject.Extensions.Factory package, see the wiki:- https:/