ninject

Ninject and MonoDroid

删除回忆录丶 提交于 2020-01-14 03:20:50
问题 Anyone had any luck getting Ninject to work on MonoDroid? i've tried the 2.0 and 4.0 mono builds from their website and also tried the .net versions. With the Mono builds i'm getting a MissingMethodException in the instantiation of my StandardKernel 回答1: I am experimenting with Ninject on a combined WP7/Monotouch/Mono for Android project and Ninject works surprisingly good. I used the latest sources, which contain a project file Ninject.WP7.csproj which seems to be outdated. It contains a lot

How to configure Ninject so that it would inject right instance depending on previously injected instance

时光毁灭记忆、已成空白 提交于 2020-01-13 14:04:38
问题 I can't find right words for my question so i will let my code speak instead. I have Repository: class Repository { public Repository(DbContext ctx) { } } then i have this bindings: Bind<IRepository>().To<Repository>(); Bind<DbContext>().To<UserStoreContext>().When... Bind<DbContext>().To<CentralStoreContext>().When... and then i have class that needs to access both db's class Foo { public Repository(IRepository userRepo, [CentralStoreAttribute]IRepository centralRepo) { } } How should i

How to configure Ninject so that it would inject right instance depending on previously injected instance

人盡茶涼 提交于 2020-01-13 14:02:18
问题 I can't find right words for my question so i will let my code speak instead. I have Repository: class Repository { public Repository(DbContext ctx) { } } then i have this bindings: Bind<IRepository>().To<Repository>(); Bind<DbContext>().To<UserStoreContext>().When... Bind<DbContext>().To<CentralStoreContext>().When... and then i have class that needs to access both db's class Foo { public Repository(IRepository userRepo, [CentralStoreAttribute]IRepository centralRepo) { } } How should i

Ninject with a base controller?

喜欢而已 提交于 2020-01-13 10:18:07
问题 I am wondering how do you do constructor inject with ninject 2.0 when you have a base controller? I have private readonly IBaseService baseService; public BaseController(IBaseService baseService) { this.baseService = baseService; } Bind<IBaseService>().To<BaseService>(); public class OtherController : BaseController { private readonly IOtherService otherService; public OtherController(IOtherService otherService, IBaseService baseService) { this.otherService = otherService; } Yet I get

Constructor injection with other, non-dependency, constructor arguments

心已入冬 提交于 2020-01-13 08:19:41
问题 I'm new to IOC containers, and I'm getting started with NInject. What do you do if you want your constructor to have parameters that are not services and don't need to be instantiated by the IOC container? For example: public class Person { private readonly string _name; private readonly IPersonRepository _repository; public Person(string name, IPersonRepository repository) { _name = name; _repository = repository; } ...... } Imagine that name is a requirement of the Person class, so, to

Using Ninject IOC to replace a factory

情到浓时终转凉″ 提交于 2020-01-13 07:42:06
问题 I've got a factory method inside a parser. Essentially as I load a token I look up the handler for that token, or drop through to the default handler. I've implemented this as a switch and as a Dictionary<string,Type> but both approaches require me to store the mapping somewhere else than the handler class. We are using Ninject for IOC and so I've realized I can also do it using kernel.Get<ITokenHandler>(tokenName); but that doesn't save me storing the information on what token the handler

Learning Inversion of Control through Dependency Injection in MVC 3

一笑奈何 提交于 2020-01-13 06:34:10
问题 Can someone please provide me a simple example of DI and IoC ? I understand the first one but was unable to get an implementation of the second one. I'm working with MVC 3 and I really want to use the IDependencyResolver, but I can't understand how. Is ninject an option or is it required? Is there a tutorial like nerdDinner and I wasn't able to find it? Can somebody give me a link to study it? 回答1: In order to grok real world DI and its patterns and anti-patterns quickly, I recommend getting

Ninject Dependency Injection in MVC3 - Outside of a Controller

情到浓时终转凉″ 提交于 2020-01-13 05:18:06
问题 We are using Ninject in our MVC3 project to do dependency injection. I used NuGet to add package references to Ninject and Ninject.MVC3 packages. When I did this it created a NinjectMVC3 class in my App_Start folder: public static class NinjectMVC3 { private static readonly Bootstrapper bootstrapper = new Bootstrapper(); public static void Start() { DynamicModuleUtility.RegisterModule(typeof(OnePerRequestModule)); DynamicModuleUtility.RegisterModule(typeof(HttpApplicationInitializationModule)

Lazy Loading of Collection - how to get the items?

ぐ巨炮叔叔 提交于 2020-01-12 18:44:33
问题 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

Solution - The entity type ApplicationUser is not part of the model for the current context

断了今生、忘了曾经 提交于 2020-01-11 07:09:08
问题 I am posting this question as documentation because it took me many hours to find this simple issue. I am taking the original MVC project generated by VS15 and attempting to modify it. Error: [InvalidOperationException: The entity type ApplicationUser is not part of the model for the current context.] 回答1: You may get this error for a variety of reasons. This is not a guaranteed fix but hopefully it will save some time for someone out there. This error shows up usually because your