inversion-of-control

Property Inject an Array with Spring.Net

不羁的心 提交于 2019-12-22 08:23:40
问题 I've been using the Spring.Net IoC container and can use it to inject properties that are of type IList and even IList<T> but I'm a bit stumped as to how to inject a property thats of type string[] . There doesn't seem to be an <array> element defined in the XSD's and using <list> <value> </list> doesn't work either. If anyone could post the xml I need to inject using an array for a property it'd be much appreciated 回答1: As mentioned here in the documentation you can inject a string array as

Register string value for concrete name of parameter

为君一笑 提交于 2019-12-22 08:19:01
问题 I am using Autofac and I have several classes which ask for parameter of type string and name lang. Is there a way to register a string value to all parameters named "lang", so it resolves automatically? I do not want to edit any of the constructors, since it is not my code (I know accepting e.g. CultureInfo would make registration easy..) Something resulting in short syntax like builder.Register(lang => "en-US").As().Named("lang") would be ideal. Thank you. 回答1: A fairly simple way to solve

How do I inject a constructor dependency into a ViewModel using Xamarin and Autofac?

本秂侑毒 提交于 2019-12-22 05:26:07
问题 I have a ViewModel and I want to inject another Class into it. I am using Visual Studio with the latest version of Xamarin. I'm using Autofac for registering en resolving dependencies. But I'm new to it and I'm facing a problem which I can't find the solution to, even though it's probably simple. This is the Class in which I want to inject another Class: public IMessagingCenterWrapper MessagingCenterWrapper; public LoginViewModel(IMessagingCenterWrapper messagingCenterWrapper){

Koin how to inject outside of Android activity / appcompatactivity

本秂侑毒 提交于 2019-12-22 03:25:24
问题 Koin is a new, lightweight library for DI and can be used in Android as well as in standalone kotlin apps. Usually you inject dependencies like this: class SplashScreenActivity : Activity() { val sampleClass : SampleClass by inject() override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) } } with the inject() method. But what about injecting stuff in places where Activity context is not available i.e. outside of an Activity ? 回答1: There is the KoinComponent

Koin how to inject outside of Android activity / appcompatactivity

喜夏-厌秋 提交于 2019-12-22 03:25:07
问题 Koin is a new, lightweight library for DI and can be used in Android as well as in standalone kotlin apps. Usually you inject dependencies like this: class SplashScreenActivity : Activity() { val sampleClass : SampleClass by inject() override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) } } with the inject() method. But what about injecting stuff in places where Activity context is not available i.e. outside of an Activity ? 回答1: There is the KoinComponent

MVC 6 IUrlHelper Dependency Injection

好久不见. 提交于 2019-12-22 03:24:56
问题 I want to use IUrlHelper through dependency injection to be able to use its functionality to generate uris for different rest endpoints. I cant seem how to figure out how to create a UrlHelper from scratch because it changed in MVC 6 and MVC doesnt automatically have that service available in the IoC controller. The setup is my Controller take in an internal model to api model converter class and that uses the IUrlHelper (all through Depenedency Injection). If there is a better alternative to

Explain the mysterious world of IoC and automatic Dispose

允我心安 提交于 2019-12-22 00:52:40
问题 I'm ASP.NET MVC newbye and I'm learning and experimenting Enterprise design patterns: very interesting and helpful things indeed! But I keep missing something about the concept of disposing resources. To be more specific want to focus on the mechanism of controllerFactory which injects in the controller constructor an implementation of IFuncyRepository or IFuncyService or anyother kind of "resource" to be used in the controller (In my case I'm using StructureMap as IoC). My question is WHERE

Should infrastructure dependencies be injected?

此生再无相见时 提交于 2019-12-21 17:54:01
问题 With infrastructure items like loggers, security, configuration and so forth, should these things really be injected to every class that needs them or should they be injected into a service locator and then the classes can use the service locator to resolve the dependencies (or some other mechanism)? It just looks really ridiculous with all classes having 10 parameter ctors to satisfy dependencies via DI. Its a code smell IMO. I can understand things like repositories or service proxies

MVC Integration tests with Unity IoC

瘦欲@ 提交于 2019-12-21 17:31:47
问题 Am trying Unity IoC, after using constructor based DI. Problem is trying to get integration tests working. http://patrick.lioi.net/2013/06/20/streamlined-integration-tests/ "Running your integration tests should exercise as much of the real system as is reasonably possible" Patrick above describes setting up an IoC inside the MVC Unit test project.. but I'm stuck as to how to implement public class HomeController : Controller { readonly IWinterDb db; // Unity knows that if IWinterDb interface

What are “High-level modules” and “low-level modules” (in the context of Dependency inversion principle)?

蹲街弑〆低调 提交于 2019-12-21 10:16:27
问题 I was reading Wikipedia's definition of Dependency inversion principle, and it uses two terms High-level modules and low-level modules , which I wasn't able to figure out. What are they and what does Dependency inversion principle have to do with them? 回答1: The definition of those are given in the introductory sentence: high level: policy setting low level: dependency modules. In laymen's terms: high level modules depend on low level modules, but shouldn't depend on their implementation. This