inversion-of-control

Ninject 2.1 ActivationException : Error activating string

我的未来我决定 提交于 2019-12-08 18:29:03
问题 I am confused about why I am receiving "Ninject.ActivationException : Error Activating string No matching bindings are available, and the type is not self-bindable" in random bindings. If I leave the binding for IMedia in place it will throw the ActivationException, but if I use the CallbackProvider it works. All of these classes are structured the same with a few different properties. I'm confused as to why ILocationType, IMedia, and IFarmDataContext throw ActivationException while the

IoC/DI Container that supports Compact Framework

主宰稳场 提交于 2019-12-08 18:01:12
问题 Is their any IoC controllers available that will work on .NET Compact Framework? 回答1: http://code.google.com/p/compactcontainer/ http://ninject.org/ 回答2: The OpenNETCF IoC framework supports the Compact Framework (as a first-class citizen), the full desktop framework, Mono for Android, MonoTouch and Windows Phone. It's also still active, with updates and fixes still being applied which can't be said about all of the other "CF supporting" frameworks. 回答3: Ninject is a dependency injection

DI CompositionRoot with multi service WCF Host

故事扮演 提交于 2019-12-08 17:29:45
We are developing a selfhosted WCF service host which will be loading services dynamically based on configuration. I was wondering wether I should consider each service as a mini app and use composition root in each hosted service or use composition root on the service host itself? Your input is much appreciated! Having a composition root per service is fine, but if you can, let your WCF service just contain 1 service with 2 methods: One method that allows you to execute query objects, one method that allows you to execute commands. This way you will still have one Composition Root for your

Windsor Ioc container: How to register that certain constructors take different implementation of an interface

风格不统一 提交于 2019-12-08 10:03:09
问题 I have lots of classes that take an IMyService as a constructor argument. e.g. ClassA(IMyservice myservice) // this should take a Concrete1 for IMyService ClassB(IMyservice myservice) // this should take a Concrete2 for IMyService How do I do my registration so that ClassB gets a Concrete2 and ClassA gets a Concrete1? Plus, is there a way to make one the default and only specify the instances that deviate from the default? (As the majority will take a Concrete1 and only a small number will

DI CompositionRoot with multi service WCF Host

核能气质少年 提交于 2019-12-08 09:56:32
问题 We are developing a selfhosted WCF service host which will be loading services dynamically based on configuration. I was wondering wether I should consider each service as a mini app and use composition root in each hosted service or use composition root on the service host itself? Your input is much appreciated! 回答1: Having a composition root per service is fine, but if you can, let your WCF service just contain 1 service with 2 methods: One method that allows you to execute query objects,

How to organize DI Framework usage in an application?

风格不统一 提交于 2019-12-08 09:31:33
问题 EDIT: I forgot to move the kernel into a non-generic parent class here and supply a virtual method to access it. I do realize that the example below, as is, would create a plethora of kernel instances. I just learned how to do injection this past week and here's how I've got things set up currently: using Ninject; using System.Reflection; namespace Infrastructure { public static class Inject<T> { static bool b = Bootstrap(); static IKernel kernel; static bool Bootstrap() { kernel = new

Register generic types with constructor in SimpleInjector how?

情到浓时终转凉″ 提交于 2019-12-08 09:23:49
问题 I use Microsoft Unity as IoC container and wrote some code like this: public static void RegisterTypes(IUnityContainer container) { MyContext ctx = new MyContext (); // is EntityFramework DbContext container.RegisterType(typeof(IEntityRepository<>), typeof(EntityRepository<>), new InjectionConstructor(ctx)); container.RegisterType(typeof(IEntityService<>), typeof(EntityService<>)); } It works for me without problem, but I want to know how to write its equivalent in SimpleInjector . 回答1: There

IoC vs global variable in library

久未见 提交于 2019-12-08 09:10:52
问题 So say that I have type that takes some parameters in the constructor, like this: public MyType(IComObject wrapper,string table) {} now IComObject is a wrapper over a two different COM objects. All(90%) of my types have to use IComObject, so in good DI fashion (to allow for testing) I am passing IComObject into every type that needs it. The main problem is that when someone goes to use my COM wrapper library that have to pass an instance of IComObject into everything they do which makes the

Using StructureMap for dependency injection to SignalR 2.0.1

ぃ、小莉子 提交于 2019-12-08 08:34:32
I'm trying to use StructureMap for dependency injection to a SignalR hub. Many sources in the internet say this should be done as in this answer: How do you Resolve signalR v2.0 with StructureMap v2.6 . I tried it, and got it to work - at least for the first action after the first pageload. When I try to leave the HTML page that includes the SignalR-JS-Code (or reload the page), or when I use one of the functions defined in my hub a second time, I get this StructureMapException: You cannot use the HttpContextLifecycle outside of a web request. Try the HybridLifecycle instead. in the public

C#, Autofac: NamedParameter is not provided in Register<>

╄→尐↘猪︶ㄣ 提交于 2019-12-08 08:33:02
问题 I'm trying some autofac features at the moment and are struggling with the NamedParameter. I created a very simple example, where IFoo is realized by HappyFoo and SadFoo . IFooUser expects an IFoo object in the constructor and uses it to print something to the console. The code below shows how I'm trying to build a IFooUser object which shall use an IFoo object based on a 'score' value. var builder = new ContainerBuilder(); builder.RegisterType<NormalFooUser>().As<IFooUser>(); builder