ninject

Using Ninject with mocks in F#

♀尐吖头ヾ 提交于 2019-12-13 18:36:03
问题 This question is part of larger question that can be found here As in out production code we use Ninject and constructor injection our services tend to look like this public class Service : IService { private readonly IRepository _repository; public Service(IRepository repository) { _repository = repository; } public Task<IEnumerable<SelectOption>> GetAlLogicOptions() { return _repository.GetOptionsAsync(); } } how ever list of constructor parameters may and will change over time. This is the

Ninject - Injecting singleton

*爱你&永不变心* 提交于 2019-12-13 18:23:17
问题 I have this error when clicking a link on a site I'm creating Error activating IEntityCache using binding from IEntityCache to EntityCache No constructor was available to create an instance of the implementation type. Activation path: 4) Injection of dependency IEntityCache into parameter entityCache of constructor of type AlbumRepository 3) Injection of dependency IAlbumRepository into parameter albumRepository of constructor of type AlbumService 2) Injection of dependency IAlbumService into

Using a parameterless controller constructor with Ninject?

孤人 提交于 2019-12-13 18:13:33
问题 I'm using Ninject for dependency injection in my application. Here's an example of one of my controllers: public class DepartmentsController : Controller { private IDepartmentsRepository departmentsRepository; public DepartmentsController(IDepartmentsRepository departmentsRepository) { this.departmentsRepository = departmentsRepository; } ... } I'm also trying to follow this tutorial to use ELMAH in an MVC application. The idea is to use a custom controller factory to handle errors from every

Convert this Castle Windsor Installer to Ninject to register all repositories

蹲街弑〆低调 提交于 2019-12-13 17:24:26
问题 I have this in my MVC2 app but I think I might move to Ninject as its becoming more popular and Castle Windsor seems a tad over complicated. How would I do something like this in Ninject however? Maybe Castle Windsor is more developed and I should stick with it. container.Register(AllTypes.FromThisAssembly() .Where(type => type.Name.EndsWith("Repository")) .WithService.DefaultInterface() .Configure(c => c.LifeStyle.PerWebRequest)); 回答1: What you want to do can be done with the Ninjec

How to unbind a concrete self-bound singleton binding in Ninject 3?

自闭症网瘾萝莉.ら 提交于 2019-12-13 16:49:31
问题 I'm currently testing some IoC frameworks for a project, and I'd love to be able to use Ninject 3. I'm running into an issue where after I configure a binding to a concretely typed singleton, I can't seem to effectively unbind the service type later on. That is, StandardKernel.TryGet<T>() returns a non-null value after calling StandardKernel.Unbind<T>() . See the snippet below for my exact usage. Is this a bug in Ninject 3, or is there something I'm missing? As a workaround, I can simply

Ninject - Kernel in static class?

点点圈 提交于 2019-12-13 13:49:11
问题 Is it right at all to "wrap" a StandardKernel with the required NinjectModule s in a static class in a separate, shared library, and use that same library whenever injection is needed (instead of instantiating a new kernel everytime)? Edit: I am trying to use Ninject from within the WCF service I am developing at the moment. (Please bear with me if what I am saying is completely rubish since I just started learning about DI and IoC containers) 回答1: See https://github.com/ninject/ninject

Can Ninject use an anonymous delegate (func) as a ConstructorArgument?

时间秒杀一切 提交于 2019-12-13 10:17:05
问题 I have a repository abstract class that encapsulates pretty much all of the CRUD functionality: public abstract class DataRepository<T> : IRepository<T> where T : class { public DataContext Context { get; private set; } public TransactionScope Transaction { get; private set; } /// <summary> /// A <see cref="bool"/> function that compares the keys for fetching a single item, for example: /// return item1.Id == item2.Id (as an anonymous delegate). /// </summary> public Func<T, T, bool>

Ninject does not trigger method when binding to method?

感情迁移 提交于 2019-12-13 07:36:45
问题 The ViewModel depends on a list of MyObject which is bound to a Repository method that looks like it never gets called? CompositionRoot public sealed class CompositionRoot { public CompositionRoot(IKernel kernel) { if (kernel == null) throw new ArgumentNullException("kernel"); this.kernel = kernel; } public void ComposeObjectGraph() { BindRepositoriesByConvention(); BindDomainModel(); } private void BindDomainModel() { kernel .Bind<IList<MyObject>>() .ToMethod(ctx => ctx.Kernel.Get

Using WithConstructorArgument and creating bound type

笑着哭i 提交于 2019-12-13 06:21:35
问题 I have a binding that looks like this: kernel.Bind<IRepository<Holiday>>().To<RepositoryBase<Holiday>>(); The problem is that RepositoryBase takes a contructor paramter of UnitOfWork called context. This is not, in and of itself a problem. Ninject should resolve it. Except for the fact that I have two UnitOfWork implementations, both bound using an attribute discriminator. kernel.Bind<IUnitOfWork>().To<MS_DevEntities>().WhenTargetHas<MsDataAttribute>() .InRequestScope(); How can specify that

NInject Load modules after the runtime is done

故事扮演 提交于 2019-12-13 05:29:20
问题 I would like to load module in asp.net mvc dynamically after the runtime is realized. So I follow many tutorials and different ways to do it. Finally I found the solution from http://www.squarewidget.com/pluggable-architecture-in-asp.net-mvc-4. I follow the code described and I try to load the assembly later. I use the class NInjectWebCommon.cs All lib have been loaded from the bin path project. I add the plugin.dll : it's the module and when I try to browse the index page from the module it