contextual-binding

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

Ninject Contextual Binding at RunTime

。_饼干妹妹 提交于 2020-01-01 11:48:17
问题 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

Ninject contextual binding for 2+ dependent classes w/ different names for same constructor param

删除回忆录丶 提交于 2019-12-13 02:26:28
问题 Having trouble figuring out how to manage contextual binding in the scenario where two classes have the same underlying interface dependency, but each class ctor's parameter is named differently. Pseudo code below to demonstrate my situation: interface IThing { } public class Thing1 : IThing { public Thing1(string fileCode) { } } public class Thing2 : IThing { public Thing2(string fileCode) { } } interface IThingFactory { IThing CreateThing(string fileCode); } interface IDependentThing { }

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