ninject

Dependency injection in BAL without adding a project reference to DAL

拥有回忆 提交于 2019-12-11 06:36:18
问题 This is related to question posted here. My Core project has following . public interface IRepository<T> : IDisposable { IQueryable<T> All { get; } IQueryable<T> AllIncluding(params Expression<Func<T, object>>[] includeProperties); TEntity Find(int id); void InsertOrUpdate(T entity); void Delete(int id); void Save(); } public class Customer { public int Id { get; set; } public string FirstName { get; set; } public string LastName { get; set; } } DAL has CustomerContext and CustomerRepository.

Handling application settings with ninject and convention based binding

荒凉一梦 提交于 2019-12-11 06:24:03
问题 I am using Ninject in an MVC3 application and am trying to switch over to conventions based binding with ninject.extensions.conventions. Now let's say I have a class that needs access to application settings such as: public class Foo : IFoo { public Foo(string connectionString) { ... } } I think I understand how to do normal binding with Ninject like this: Bind<IFoo>() .To<Foo>() .WithConstructorArgument( "connectionString", ConfigurationManager.ConnectionStrings["Default"].ConnectionString);

Dependency Injection to CustomFormatter

百般思念 提交于 2019-12-11 05:56:13
问题 I am working in webapi with ninject as dependency injector. All my constructor injection working fine for my controllers. I have custom mediatype formatter which used to return pdf when user requested for 'application/pdf' Here i need to update data after create pdf. So here i need to call my business class to update data. MyCustomFormatter Code: public class PdfMediaTypeFormatter : MediaTypeFormatter { private readonly string mediaType = "application/pdf"; Func<Type, bool> typeisIPdf = (type

Running Unit Test having Operation could destablize the runtime exception at new StandardKernel

久未见 提交于 2019-12-11 05:52:08
问题 In our unit tests where it first load db setting from a singleton class, we have: IKernel kernel = new StandardKernel(new OurInfrastructureNinjectModule()); _myService = kernel.Get<MyService>(); // To inject a concrete to myService It runs fine in our mvc application, however, exception threw when it is called by unit tests. 回答1: Note: I work at Typemock Due to changes in security in .NET 4, there was a bug in Typemock Isolator where code running from assemblies marked with

How to extend Ninject Binding Syntax

只愿长相守 提交于 2019-12-11 05:36:57
问题 is there a way to extend the existing binding syntax (e.g. extension method) that will allow us to have something like this: Bind<IRepository>().ToProvider<MyProvider<MyRepository>>().WhenCustom<SomeType>() 回答1: Write an extension method for IBindingWhenSyntax<T> and use the existing When overload to implement your logic: class BindingWhenExtensions { public IBindingInNamedWithOrOnSyntax<T> WhenCustom<T>( this IBindingWhenSyntax<T> syntax) { return syntax.When(r => true); } } 回答2: Reframing

Help with action filters in asp.net mvc 3

空扰寡人 提交于 2019-12-11 05:35:23
问题 I want to create an action filter that will be used by ONLY two controllers in my app... This action filter is supposed to be checked for every action inside the TWO controllers. Heres my action filter code public class AllowedToEditEHRFilter : IActionFilter { IUnitOfWork unitOfWork; IRepository<EHR> ehrRepository; public AllowedToEditEHRFilter(IUnitOfWork dependency) { unitOfWork = dependency; ehrRepository = unitOfWork.EHRs; } public void OnActionExecuting(ActionExecutingContext

Safely making wide-reaching change to IoC/DI config

五迷三道 提交于 2019-12-11 05:09:52
问题 Specific Question: How can I unit Test my DI configuration against my codebase to ensure that all the wiring up still works after I make some change to the automated binding detection. I've been contributing to a small-ish codebase (maybe ~10 pages? and 20-30 services/controllers) which uses Ninject for Ioc/DI. I've discovered that in the Ninject Kernel it is configured to BindDefaultInterface . That means that if you ask it for an IFoo, it will go looking for a Foo class. But it does that

Ninject.MVC5 Release Scope Never Called - OutOfMemoryException

白昼怎懂夜的黑 提交于 2019-12-11 05:00:42
问题 I'm new to Ninject, but I've become convinced that the out of the box configuration for Ninject.MVC5 NuGet package never actually releases the objects scoped to the HttpContext. I consistently get an OutOfMemoryException after a bout of repeated heavy memory usage by some of my larger reports. So to prove I wasn't losing my mind I created an empty test project. I created a default project in VS 2017 by File -> New Project -> C# -> Web -> ASP.NET Web Application -> MVC (in the modal). This is

Issue Rebind NInject while dynamically change the connection string

故事扮演 提交于 2019-12-11 04:43:35
问题 In connection string i should dynamically passing the loggeduserid value by using the attribute application name=userid in connection string and getting into SQL Server by using the query select app_name(). Technologies used: 1).net 4.0 2)NHibernate 3)Ninject Before logged-in i am using Ninject IoC container and NHibernate to load the connection string without the application name attribute and after logged in I am passing the logged user id as a constructor value and rebinding the

ASP.NET MVC 5 Ninject: Ninject.MVC3/5

早过忘川 提交于 2019-12-11 04:06:53
问题 I want to add Ninject to an ASP.NET MVC 5 Project. NinjectWebCommon.cs is not in the App_Start folder. In a tutorial I read that Ninject.MVC3 should be added via Nuget. If I go into 'Manag NuGet Packages' and search for 'Ninject' I get the following: There I find 'Ninject.MVC5'. A symbol indicates that this package is installed. But when I go to 'Installed packages' I see the following: Here I cannot find this package. Why is the package not listed here? Should I install 'Ninject.MVC3'