ninject

Does Ninject Conventions only work for public classes?

久未见 提交于 2019-12-04 05:22:36
问题 I started using Ninject for my project, to automatically bind all subclasses of an abstract class. The binding for this is -- nice and easy -- as follows: kernel.Bind(x => x.FromThisAssembly() .SelectAllClasses(). .InheritedFrom<AbstractGenerator>() .BindBase()); However, I found that this doesn't work. After some experimenting I found that the reason for this not working is that all my implementations (and the abstract class) are marked internal . I could imagine this to be some security

Ninject binding with generic repository MVC returns error on Parameterless Constructor

强颜欢笑 提交于 2019-12-04 05:19:45
问题 I'm trying to use a fairly simple generic repository for a number of administration lists in an application. Functionality for the admin users is just CRUD to keep the lists up to date for use elsewhere as lookups. I keep getting an error of the form: An error occurred when trying to create a controller of type 'WhatWorks.Controllers.AchievementController'. Make sure that the controller has a parameterless public constructor. I've read an awful lot of posts on SO and blogs found through

In Ninject, how can I run custom code on an object after it is created with Bind<..>.ToSelf()?

我的未来我决定 提交于 2019-12-04 05:16:29
In Ninject's dependency injection, if you set up a binding of a class to itself like so: Bind<SomeClass>().ToSelf(); Ninject very nicely resolves any dependencies SomeClass has and gives you the object back. I want to be able to do something to the SomeClass it returns every time it creates a new one, so like a post-processing event. I could use the .ToMethod (or ToFactoryMethod) binding to explicitly new it up, but I would like all its dependencies resolved by Ninject beforehand. It wouldu be nice to do something like: Bind<SomeClass>() .ToSelf() .After(sc => sc.MethodIWantToCall()); // then

Castle Windsor Typed Factory Facility equivalents

一世执手 提交于 2019-12-04 05:12:42
do any other .NET IoC containers provide equivalent functionality to the typed factory facility in Castle Windsor? e.g. if I am using an abstract factory pattern in a WPF application: public class MyViewModel { private IAnotherViewModelFactory factory; public void ShowAnotherViewModel() { viewController.ShowView(factory.GetAnotherViewModel()); } } I don't want to have to create a manual implementation of IAnotherViewModelFactory for every type of ViewModel I wish to show, I want the container to take care of this for me. AutoFac has a feature called Delegate Factories , but as far as I can

Lazy Loading of Collection - how to get the items?

别来无恙 提交于 2019-12-04 05:02:19
I have a simply Class that is intended to be a simple POCO - it just holds data. With one exception: It contains a Collection of Notes. I want to lazy-load this collection so that I don't have to fetch the Notes on Pages that don't need them. The stub for this is this: public class MyDTOClass { private ICollection<Note> _notes = null; public ICollection<Note> Notes { get { if(_notes == null) { // Get an INoteRepository and initialize the collection } return _notes; } } } Now, I'm wondering how to proceed from here. It's an ASP.net MVC application and I use Dependency Injection to inject the

Convention based binding of constructor string arguments with Ninject

十年热恋 提交于 2019-12-04 04:13:26
I'm using Ninject as IoC container in my project. I have following class: public class SomeRepository:ISomeRepository { public SomeRepository(string someDatabaseConnectionString) { // some code here.. } } In my application settings file I have connection string named "someDatabase". By default the one should add following configuration in order to inject this connection string into the constructor: kernel.Bind<ISomeRepository>() .To<SomeRepository>() .WithConstructorArgument("someDatabaseConnectionString", connString); But i want to implement conventional based binding of such strings. Values

Ninject: Can modules be loaded that are declared as internal

。_饼干妹妹 提交于 2019-12-04 04:06:15
Is it at all possible to configure Ninject to load modules that have been declared as internal ? I have tried configuring InternalVisibleTo for the Ninject assembly, but this does not help. I can of course make the modules public , but really they should be internal . mrydengren Internally KernalBase.Load(IEnumerable<Assembly assemblies) uses the GetExportedTypes() which only returns public types. However, you could write your own "NinjectModule scanner". public static class NinjectModuleScanner { public static IEnumerable<INinjectModule> GetNinjectModules(IEnumerable<Assembly assemblies) {

Exception when adding a View to MVC3

给你一囗甜甜゛ 提交于 2019-12-04 03:43:34
问题 I'm using Visual Studio 2012 Express for Web. When I try to add a view, I get an error saying: The templates had the following 1 error(s) C:\Program Files\Microsoft Visual Studio 11.0\Common7\IDE\VWExpress\ItemTemplates\CSharp\Web\MV C 3\CodeTemplates\AddView\CSHTML\Empty.tt(-1,-1): error : There was a problem getting an AppDomain to run the transformation from the host. The process cannot continue. I've been plugging in Ninject (this is actually just an app to prove it's working) so it could

How to use Ninject to inject services into MVC 3 FilterAttributes?

主宰稳场 提交于 2019-12-04 03:40:43
问题 I'm writing a custom ErrorHandler attribute for my MVC project. I would like to inject an implementation of EventViewerLogger into that attribute. I'm using Ninject 2.2 and it works fine for other features, such as injection repositories and aggregate services through controller constructors. I understand that I can't inject an implementation of some class into attribute through constructor, therefore I have to inject it into the attribute's property. Interface is below: namespace Foo.WebUI

No matching bindings are available, and the type is not self-bindable in Ninject

北战南征 提交于 2019-12-04 03:08:48
I am using Ninjec, Ninject.Web.MVC and Ninject.Web.Common When I start my mvc application I get this binding error: What do I wrong in my binding? Error activating DbConnection No matching bindings are available, and the type is not self-bindable. Activation path: 4) Injection of dependency DbConnection into parameter existingConnection of constructor of type DbContext 3) Injection of dependency DbContext into parameter dbContext of constructor of type GenericRepository{User} 2) Injection of dependency IGenericRepository{User} into parameter repo of constructor of type HomeController 1)