dependency-injection

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

Why use IKernel over IWindsorContainer?

旧巷老猫 提交于 2019-12-22 03:22:45
问题 I have seen in several code examples where people have used IKernel rather than use IWindsorContainer . Why is this? Here is one example: http://docs.castleproject.org/(S(kwaa14uzdj55gv55dzgf0vui))/Windsor.Windsor-tutorial-part-two-plugging-Windsor-in.ashx In the above example it came to bite me because I added a subresolver Container.Kernel.Resolver.AddSubResolver( new CollectionResolver(Container.Kernel, true)); that will allow me to inject collections... but yet it wasnt working. I figured

No implementation was bound - Java Guice

六眼飞鱼酱① 提交于 2019-12-22 01:53:48
问题 Novice here trying to use a dummy Java Facebook app that uses Guice to inject a database dependency into the Facebook factory but continue to have Guice error out telling me: ### No implementation for com.example.storage.Db annotated with @com.example.storage.annotations.SystemDb() was bound while locating com.example.storage.Db annotated with @com.example.storage.annotations.SystemDb() for parameter 0 at com.example.facebook.client.exceptions.FacebookExceptionHandlerDb at com.example

Dynamically choose dependency without if else

北战南征 提交于 2019-12-22 01:31:53
问题 How can i choose dependency without if else condition. Suppose i have a interface: public interface A{ String doSomething(String req); } there are two service implements A : @Component public class FirstImpl implements A{ @override String doSomething(String req){ return "something"; } } and: @Component public class SecondImpl implements A{ @override String doSomething(String req){ return "something"; } } Now i create a AdapterService class: @Component public class AdapterService{ @Autowired

Dependency injection with factory class

六眼飞鱼酱① 提交于 2019-12-22 01:15:58
问题 We have a request based application where requests are executed by sending a command over serial. When data is received indicating a request is to be performed the request is created using a factory class by specifying that requests specific ID. The problem is that each request will have different dependencies depending on the tasks it has to perform and I am looking for the best solution to do this. What is the best way to inject dependencies to requests when dependencies may differ between

Using Guice, how can I inject a bounded-wildcard class?

我的梦境 提交于 2019-12-21 23:41:00
问题 Using Guice, I want to inject a bounded-wildcard class. To be clear, I don't want to inject an object , but inject a class type . The would read: class A { Class<? extends SuperClass> a; @Inject A(Class<? extends SuperClass> a) { this.a = a.; } } How can I correctly bind the parameter? 回答1: Use this binding: bind(new TypeLiteral<Class<? extends SuperClass>>() {}) .toInstance(SubClass.class); 来源: https://stackoverflow.com/questions/8734826/using-guice-how-can-i-inject-a-bounded-wildcard-class

Custom ControllerFactory with autofac

混江龙づ霸主 提交于 2019-12-21 23:26:24
问题 First of all i am a newbie in asp mvc so please be patient. Currently I want to create project where autofac will be IoC container i will reqister custom controller factory. In custom controller factory I want to set implementation Data Repository via constructor of controller. I thought it should be done in that way: ContainerBuilder builder = new ContainerBuilder(); builder.RegisterControllers(asm).InstancePerHttpRequest(); builder.Register(s => new ControllerFactory()).As

How to peek at message while dependencies are being built?

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-21 22:41:53
问题 I building multitenancy into the unit of work for a set of services. I want to keep the tenancy question out of the way of day-to-day business domain work, and I do not want to touch every existing consumer in the system (I am retrofitting the multitenancy onto a system without any prior concept of a tenant). Most messages in the system will be contexted by a tenant. However, there will be some infrastructure messages which will not be, particularly for the purpose of automating tenant