ninject

Make sure that the controller has a parameterless public constructor using Ninject

為{幸葍}努か 提交于 2019-12-04 12:22:10
Here is the issue at hand: While calling my CustomerController through the URL , I get the following exception: ExceptionMessage: An error occurred when trying to create a controller of type 'CustomerController'. Make sure that the controller has a parameterless public constructor. I am using the following url's: http://localhost:55555/api/Customer/ http://localhost:55555/api/Customer/8 Please note: The /api/Customer/ call were working before I refactored the logic into a business class and implemented dependency injection. My research suggests that I am not registering my interface and class

Multi-step database transaction split across multiple HTTP requests

荒凉一梦 提交于 2019-12-04 12:19:55
问题 I have used TransactionScope in the past with desktop client applications to roll back an incomplete multi-step transaction. That approach would seem unlikely to work in an Web application. Can anyone suggest ways in which multiple steps, across several pages, can be ensured to roll back if the entire process is not completed? (their browser crashes or they close the browser in mid process for example) Certainly, i could write to a temp table of some sort, then transfer the final record to

Disable implicit binding/injection of non explicitly bound classes in Ninject 2+

随声附和 提交于 2019-12-04 11:41:26
问题 If you request an unbound object from NInject, then the default behaviour is (if a suitable constructor is available) appears to be to create an instance of the appropriate object. I'd like to disable this behaviour (I had a difficult to debug issue because something was auto-bound instead of picking up my custom binding in a module). This question hints that it is possible, but I'm unable to find the answer from the NInject wiki. 回答1: Remove the SelfBindingResolver from the kernel components

How to tell Ninject to bind to an implementation it doesn't have a reference to

与世无争的帅哥 提交于 2019-12-04 11:17:02
问题 I'm using NinjectMVC3 in my ASP.NET MVC3 project. I have 3 layers Foo.Web Foo.Services Foo.Data Foo.Web references Foo.Services but not Foo.Data. One of my services looks like this public class FooService : IFooService { private readonly IFooRepository _fooRepository; public FooService(IFooRepository fooRepository) { _fooRepository = fooRepository; } // ... } NinjectMVC3 executes this bootstrapping method in the Foo.Web startup private static void RegisterServices(IKernel kernel) { kernel

C#, Ninject: Where do you put the kernel and your modules?

谁都会走 提交于 2019-12-04 10:48:21
问题 I'm creating a tiny C# application, which currently consists of a core assembly and a winforms assembly. I realize I probably don't really need Ninject in a small thing like this, but I would like to try it out. Anyways, to work with Ninject I have understood that you would write a set of modules, which maps class is returned and so on. After that you would create an instance of IKernel and load your modules into that. But, where do I keep those modules? And where do I keep the kernel? Where

Letting Ninject manage my transaction state, practice concerns

余生长醉 提交于 2019-12-04 10:47:27
问题 I'm letting Ninject manage my ISession and ITransaction state in Fluent nHibnerate with the following registration method - I am wondering if it is sufficient control of transactions, or whether I need to be putting this somewhere else. The thought is that each ISession is created on a request, and that Ninject handles the commit of everything done during that request. public class SessionModule : Ninject.Modules.NinjectModule { private static ISessionFactory sessionFactory; public override

Membership reboot replace Ninject with Simple Injector

谁都会走 提交于 2019-12-04 10:36:08
I need add membership reboot (RavenDb) into the project that use IOC Simple Injector Ninject implementation var config = MembershipRebootConfig.Create(); kernel.Bind<MembershipRebootConfiguration<HierarchicalUserAccount>>().ToConstant(config); kernel.Bind<UserAccountService<HierarchicalUserAccount>>().ToSelf(); kernel.Bind<AuthenticationService<HierarchicalUserAccount().To<SamAuthenticationService<HierarchicalUserAccount>>(); kernel.Bind<IUserAccountRepository<HierarchicalUserAccount>>().ToMethod(ctx => new BrockAllen.MembershipReboot.RavenDb.RavenUserAccountRepository("RavenDb")); kernel.Bind

Ninject Contextual Binding at RunTime

烈酒焚心 提交于 2019-12-04 09:45:35
I am trying to understand Ninject Contextual Binding. I understand the scenarios where I know my context at design time. e.g. I understand that I can use Named Attributes to Bind the DB object to a mock DB when I want to use it in a test class and to a SQL DB when I use it from my actual code. However, I don't know how to handle contextual Binding at runtime. e.g. let's say I am writing software for a shopping center. The shopkeeper can use a keyboad for billing or a barcode scanner. I don't know which one he will use beforehand. And he might add other ways of scanning like RFID sometime in

Using Prism with Ninject

江枫思渺然 提交于 2019-12-04 09:28:11
问题 Is anyone out there using the Prism framework with Ninject instead of Unity? I need some functionality Unity isn't supporting yet, and I've decided to switch the IoC container to Ninject. I'm struggling a bit with the replace though.. What I need to use from Prism is the EventAggregator and the RegionManager. I have seen this sample that actually does the replace, but this is written for an older version of Prism, and several of the classes seems to have changed etc. So I ended up all

Ninject - The resource cannot be found

不打扰是莪最后的温柔 提交于 2019-12-04 09:25:30
I get error The resource cannot be found. When I try to implement Ninject in my MVC-3 application. The problem appears to be coming from Global.asax during CreateKernel() #region Inversion of Control protected override IKernel CreateKernel() { return Container; } static IKernel _container; public static IKernel Container { get { if (_container == null) { _container = new StandardKernel(new SiteModule()); } return _container; } } internal class SiteModule : NinjectModule { public override void Load() { bool MOCKDB = true; //MOCKDB = false;//Stop Mocking if (MOCKDB) { //Set up mock bindings Bind