ninject

Injecting AutoMapper dependencies using Ninject

左心房为你撑大大i 提交于 2019-12-03 07:08:43
I am having trouble injecting AutoMapper into an ASP.NET MVC 2 application using Ninject. I used Jimmy Bogard's post on AutoMapper and StructureMap type Configuration as a guide. public class AutoMapperModule : NinjectModule { public override void Load() { Bind<ITypeMapFactory>().To<TypeMapFactory>(); Bind<Configuration>().ToSelf().InSingletonScope().WithConstructorArgument("mapper", MapperRegistry.AllMappers); Bind<IConfiguration>().To<Configuration>(); Bind<IConfigurationProvider>().To<Configuration>(); Bind<IMappingEngine>().To<MappingEngine>(); } } Ninject throws an exception when

Ninject and ASP.NET Web API

自作多情 提交于 2019-12-03 06:58:58
Before I set up the question you should know that I got my current code from this page: http://www.strathweb.com/2012/05/using-ninject-with-the-latest-asp-net-web-api-source/ I'm trying to use ASP.NET Web API and Ninject in my application by using an IDependencyResolver adapter found on the site above. I created all the code just like it shows on the site and it works but when I load up my appication my regular controllers fail and show this error: [MissingMethodException: No parameterless constructor defined for this object.] [InvalidOperationException: An error occurred when trying to create

Dependency Injection and development productivity

早过忘川 提交于 2019-12-03 06:58:10
Abstract For the past few months I have been programming a light weight, C# based game engine with API abstraction and entity/component/scripting system. The whole idea of it is to ease the game development process in XNA, SlimDX and such, by providing architecture similar to that of the Unity engine. Design challenges As most game developers know, there are a lot of different services you need to access throughout your code. Many developers resort to using global static instances of e.g. a Render manager(or a composer), a Scene, Graphicsdevice(DX), Logger, Input state, Viewport, Window and so

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

别来无恙 提交于 2019-12-03 06:37:17
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 do stuff go? You may create static wrapper class for kernel. That way you could do something like

Ninject crashes on application start on appharbor

我是研究僧i 提交于 2019-12-03 06:28:58
I am using Ninject on my MVC 3 project deployed on appharbor. I noticed that I get an exception when the application is started, and it looks like something inside Ninject is the cause, but I cannot find any answers out there - so please help me :) Will try to add the complete exception here: Server Error in '/' Application. Object reference not set to an instance of an object. Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. Exception Details:

Using NInject to bind a generic interface, with a default if a binding for the generic type is not set

最后都变了- 提交于 2019-12-03 06:13:59
问题 Imagine I have the following classes and interfaces: public interface IService<T> { } public class DefaultService<T> : IService<T> { } public class FooService : IService<Foo> { } public class BarService : IService<Bar> { } I would then like to be able to get instances from the Kernel like this: Kernel.Get<IService<Foo>>(); // Should return FooService Kernel.Get<IService<Bar>>(); // Should return BarService Kernel.Get<IService<Dog>>(); // Should return DefaultService Kernel.Get<IService<Cat>>(

Letting Ninject manage my transaction state, practice concerns

半城伤御伤魂 提交于 2019-12-03 06:00:28
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 void Load() { Bind<ISessionFactory>() .ToMethod(c => CreateSessionFactory()) .InSingletonScope(); Bind

How do I use AutoMapper with Ninject.Web.Mvc?

南笙酒味 提交于 2019-12-03 05:51:25
Setup I have an AutoMapperConfiguration static class that sets up the AutoMapper mappings: static class AutoMapperConfiguration() { internal static void SetupMappings() { Mapper.CreateMap<long, Category>.ConvertUsing<IdToEntityConverter<Category>>(); } } where IdToEntityConverter<T> is a custom ITypeConverter that looks like this: class IdToEntityConverter<T> : ITypeConverter<long, T> where T : Entity { private readonly IRepository _repo; public IdToEntityConverter(IRepository repo) { _repo = repo; } public T Convert(ResolutionContext context) { return _repo.GetSingle<T>(context.SourceValue);

How to use Ninject bootstrapper in WebApi OwinHost Startup?

只谈情不闲聊 提交于 2019-12-03 05:51:23
问题 I am migrating from IIS WebAPI to OwinHost. Utilizing the latest pre-release versions of nuget packages, I successfully used instructions here: https://github.com/ninject/Ninject.Web.Common/wiki/Setting-up-a-OWIN-WebApi-application Here is stub of my code: public void Configuration(IAppBuilder app) { var config = new HttpConfiguration(); config.MapHttpAttributeRoutes(); app.UseNinjectMiddleware(CreateKernel); app.UseNinjectWebApi(config); } private static StandardKernel CreateKernel() { var

Ways to setup a Ninject singleton

时光毁灭记忆、已成空白 提交于 2019-12-03 05:31:50
I have a class ( MyFacade ) that I injected parameter(s) with Ninject : class MyFacade { IDemoInterface demo; public MyFacade(IDemoInterface demo) { this.demo = demo; } public void MyMethod() { Console.WriteLine(demo.GetInfo()); } } Of course, I have to setup the Ninject to inject the appropiate implementation of my parameter ( IDemoInterface ) I know, I can instantiate MyFacade object by doing kernel.Get<MyFacade>(); without setting anything else. Currently my facade doesn't have an interface (because it is my only implementation, maybe I will add its interface for standard proposes) if I