ioc-container

Resolve one of multiple registrations with DryIoc

不问归期 提交于 2019-12-08 03:58:11
问题 Given the small example below, is there a way to mark (attribute, name convention,... ) the MyInterface argument in MyService2 , so that it will resolve correctly, or is the only way to pass in MyInterface[] ? I know that Castle Windsor can resolve it based on naming convention, but I haven't found something similar in DryIoc public interface MyInterface { } public class MyImplementationA : MyInterface { } public class MyImplementationB : MyInterface { } public class MyService1 { public

Child containers in MvvmCross IoC

℡╲_俬逩灬. 提交于 2019-12-08 03:16:55
问题 I have a WPF MVVM application that I'd like to refactor to use MvvmCross to support a WPF and Mono for Android implementations. Currently we are using Unity 3.0 for dependency injection and rely on its support for container hierarchies (one main container w/ the main view and view model and services; and for each session with a server a child container with views, view models and services that have a limited lifetime). Can the IoC in MvvmCross support child containers? If not, how would you

Generic repository lifetime configuration with Windsor

孤者浪人 提交于 2019-12-08 02:41:47
问题 I'm out of ideas how to configure right Windsor container for use with repositories in Windows app. I have generic repository implementation Repository, where T is entity type, it has a dependency IDatacontextProvider, which provides datacontext for it: public class Repository<T> : IRepository<T> where T : class { protected DataContext DataContext; public Repository(IDataContextProvider dataContextProvider) { DataContext = dataContextProvider.DataContext; } .... } And for simple things

Multiple RegisterAll registrations using the same set of singletons with SimpleInjector

[亡魂溺海] 提交于 2019-12-08 02:15:30
问题 I'm building a plugin system for an e-commerce project with Simple Injector. I'm using RegisterAll to register all implementation of a IPaymentProvider and of a IResourceRegistrar (and in the fure more). But this creates a new instance each time. Here is it suggested to use RegisterSingle on each type. But how to achieve this in this case? private static void RegisterMultipleUnderOneInterface( Container container, string name) { IEnumerable<Type> pluginRegistrations = from dll in finder

How do I use Structuremap 3 with objects that aren't friendly to constructor injection?

南楼画角 提交于 2019-12-07 22:06:49
问题 I'm moving from StructureMap 2.x to 3.x. One major change is that using ObjectFactory results in the following warning: 'StructureMap.ObjectFactory' is obsolete: 'ObjectFactory will be removed in a future 4.0 release of StructureMap. Favor the usage of the Container class for future work' So in most cases, the resolution is fairly easy: pass through IContainer as a constructor. Unfortunately this is not feasible for ASMX web serivces or attributes, both of which require a default constructor.

Set AutoFac to use PropertiesAutowired(true) as default?

天涯浪子 提交于 2019-12-07 18:12:34
问题 Is there a way i can set AutoFac to use PropertiesAutowired(true) to be the default for all types being registered. i.e. I dont want to use ".PropertiesAutowired(true)" all the time var builder = new ContainerBuilder(); builder.RegisterType<Logger>() .PropertiesAutowired(true) .SingleInstance(); 回答1: This can be done with a module, e.g. class InjectPropertiesByDefaultModule : Autofac.Module { protected override void AttachToComponentRegistration( IComponentRegistration registration,

Alternative to passing IOC container around

亡梦爱人 提交于 2019-12-07 17:33:55
问题 I had the following base class with several dependencies: public abstract class ViewModel { private readonly ILoggingService loggingService; public ViewModel( ILoggingService loggingService, ...) { this.loggingService = loggingService; ... } } In my derived class, I don't want to have to repeat all of the parameters in this base class constructor, so I did this: public abstract class ViewModel { private readonly IUnityContainer container; private ILoggingService loggingService; ... public

VS 2010 - easy way to copy full type name of a class/interface?

谁都会走 提交于 2019-12-07 17:12:01
问题 Is there a way to copy the full type name of a class/interface/etc. in Visual Studio to the clipboard? In particular, I need them for Castle Windsor configuration and would love to figure out how to do this effortlessly. (Example: highlight IInterface in the code editor and end up with My.Full.Namespace.Is.Here.IInterface on the clipboard.) VS puts the full type name in a read-only combobox in the upper left (which is utterly useless for copying purposes); does anyone know a way? (I have

How can I override a component registered in Castle Windsor?

徘徊边缘 提交于 2019-12-07 14:12:11
问题 I'm just starting with Windsor, so please be gentle :) I have a scenario where I want to be able to override/replace components placed inside a windsor container. Read on ... In my prod code, I want to be able to register a component which implements a base class, and use a container to resolve the implementer. So far, using container.Register(Component.For<LoggerBase>().ImplementedBy<DebugLogger>()); and container.Resolve<LoggerBase>(); In my tests, I'd like to add a stub/mock implementation

How to use “Composite Design Pattern” with Ninject

感情迁移 提交于 2019-12-07 13:38:26
问题 Validation Rule Contract: public interface IValidationRule { bool IsValid(); } Concrete Validation Rule: public class MyClass : IValidationRule { public bool IsValid() { return true; } } Composite: public class ValidationRuleComposite : IValidationRule { private readonly IEnumerable<IValidationRule> _validationRules; public ValidationRuleComposite(IEnumerable<IValidationRule> validationRules) { _validationRules = validationRules; } public bool IsValid() { return _validationRules.All(x => x