ninject

How to inject an action into a command using Ninject?

空扰寡人 提交于 2020-01-06 19:34:01
问题 Actually exploring the Command Pattern and finds it pretty interesting. I'm writing a WPF Windows App following the MVVM Architectural Pattern. I've begun with these post which explain the basics. Basic MVVM and ICommand usuage example Simplify Distributed System Design Using the Command Pattern, MSMQ, and .NET Now that I was able to break user actions into commands, I thought this could be great to inject the commands that I want. I noticed that the commands are found into the ViewModel in

为什么我需要一个IoC容器而不是直接的DI代码? [关闭]

半腔热情 提交于 2020-01-06 15:40:05
【推荐】2019 Java 开发者跳槽指南.pdf(吐血整理) >>> 我一直在使用 依赖注入 (DI)一段时间,在构造函数,属性或方法中注入。 我从未觉得需要使用 控制反转 (IoC)容器。 但是,我读的越多,我觉得社区使用IoC容器的压力就越大。 我使用.NET容器,如 StructureMap , NInject , Unity 和 Funq 。 我仍然没有看到IoC容器如何使我的代码受益/改进。 我也害怕在工作中开始使用容器,因为我的许多同事都会看到他们不理解的代码。 他们中的许多人可能不愿意学习新技术。 请说服我需要使用IoC容器。 当我在工作中与开发人员交谈时,我将使用这些论点。 #1楼 我是一名康复的国际奥委会成瘾者。 这些天我发现很难证明在大多数情况下使用IOC来证明其合理性。 IOC容器牺牲了编译时检查,据说可以为您提供“简单”设置,复杂的生命周期管理以及在运行时动态发现依赖关系。 我发现编译时间检查的丢失以及由此导致的运行时间魔术/异常,在绝大多数情况下都不值得花里胡哨。 在大型企业应用程序中,他们可能很难跟踪正在发生的事情。 我不购买集中化论证,因为你可以非常容易地集中静态设置,为你的应用程序使用抽象工厂,并虔诚地将对象创建推迟到抽象工厂,即做适当的DI。 为什么不这样做静态无魔法DI: interface IServiceA { } interface

NinjectControllerFactory FileLoadException Error

谁说胖子不能爱 提交于 2020-01-06 15:19:09
问题 I tried create just example porject and I want use Ninject.I create NinjectControllerFactory.cs like this using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.Mvc; using Ninject; using System.Web.Routing; using Moq; using System.Linq; using SportStore.Domain.Entities; using SportStore.Domain.Abstract; using System.Collections.Generic; using SportStore.Domain.Concrete; namespace SportStore.WebUI.Infrastructure { public class

Property injection without using attribute [Inject] with Ninject

我们两清 提交于 2020-01-06 05:50:45
问题 I have a controller and a customized ActionInvoker. I can set the customized ActionInvoker as following, public HomeController() { this.ActionInvoker = new MyActionInvoker(..); } But don't want to do this in every controller (and I don't want to use a base controller either). I want to use Ninject to inject the ActionInvoker. Since ActionInvoker is part of the base controller I can't add [inject] to it. I searched a lot and tried something like Bind<HomeController>().ToSelf()

autofac scope around a resolved instance

拈花ヽ惹草 提交于 2020-01-06 05:28:11
问题 I'm somewhat new to autofac, but have already used it successfully with different "simple" configurations. Now I'm trying something more complex and struggle with working this out. Essentially, I have an entry point where all autofac configuration is done and the first objects are resolved, which themselves get dependencies by constructor injection, their dependencies can have other dependencies and so on. Some code: public class Root { public Root(A.Factory factory) { for (int i = 0; i < 3;i

Autofac vs Ninject contextual binding?

生来就可爱ヽ(ⅴ<●) 提交于 2020-01-06 04:19:47
问题 1) Autofac and Ninject, which one is better in contextual binding? 2) With Ninject, I can bind to types in a specific namespace: Bind<A>().To<B>().When(context => context.ParentContext.Binding.Service.Namespace == "MyProject.Common"); Can I do this with Autofac? Thanks! (sorry for my English) 回答1: Of the two, only Ninject provides this functionality. It is a useful feature but Autofac excludes it to prevent fragility in other Autofac-specific features that rely on the dependency being unaware

How to make Ninject use a custom construction logic for a specific type while keeping the resolution process?

[亡魂溺海] 提交于 2020-01-05 15:28:07
问题 I have a class which accepts dependencies as constructor arguments. This class may be inherited by some other classes and due to technical reasons (about constructor order and so) I have to use a factory method and dynamic invocation using Activator.CreateInstance . The factory method is not purely infrastructural, but it has some kind of initialization logic inside. public class Foo { protected Foo(IService service, IOtherService otherService) { ... } ... public Foo Create(Type fooType,

Binding recurring connection string constructor parameters using DI

巧了我就是萌 提交于 2020-01-05 12:07:16
问题 I'm looking for advice on how best to bind a couple of connection strings which recur throughout my dependencies. Currently I have (using ninject): Bind<IFoo>().To<SqlFoo>() .WithConstructorArgument("db1ConnStr", db1ConnectionString) .WithConstructorArgument("db2ConnStr", db2ConnectionString); Bind<IBar>().To<SqlBar>() .WithConstructorArgument("db1ConnStr", db1ConnectionString) .WithConstructorArgument("db2ConnStr", db2ConnectionString); etc. which obviously is not the most elegant code. Is

Partial injection with Ninject?

自古美人都是妖i 提交于 2020-01-05 11:52:33
问题 I am trying to implement Ninject on an existing class that have a bool parameter in the constructor public MyClass(bool val) //[OPTION 1: Current] { //I Called static function to do something -> I want to inject this ... if(val){ ... } else{ ... } ... } I want to change the logic to inject ISomething .... the ctor will look like: public MyClass(ISomething something, bool val) //[OPTION 2: Desired] { something.DoSomething(); ... if(val){ ... } else{ ... } ... } Also I used a disposable class

Ninject and binding generics

微笑、不失礼 提交于 2020-01-05 06:55:08
问题 Warning : I'm just starting to explore Ninject . I have a generic DomainObject class defined as this: public abstract class DomainObject<T> : IDomainObject where T : IDomainObject { protected DomainObject(IDataProvider<T> dataProvider) { DataProvider = dataProvider; } // blah and blih protected IDataProvider<T> DataProvider { get; private set; } } As you can see in the code above, that DomainObject has a constructor expressing the dependency on a IDataProvider<T> . In my Ninject module, here