dependency-injection

ASP.NET Core MvcJsonOptions dependency injection without modified closure?

两盒软妹~` 提交于 2019-12-23 05:49:12
问题 (This question is similar to ASP.NET Core MvcOptions dependency injection without modified closure? However, I struggle to apply the solution of that question to this one.) In my ASP.NET Core 1.1.3 project, I currently inject an ITraceWriter dependency into MvcJsonOptions in the ConfigureServices method in the following way: public override IServiceProvider ConfigureServices(IServiceCollection services) { services.AddProjectSpecificStuff(); ITraceWriter traceWriter = null; services.AddMvc()

.Net Core 2.0 Webjob with Scoped Dependencies

允我心安 提交于 2019-12-23 05:42:09
问题 I am building a webjob with .Net Core 2.0 set up using an IJobActivator. IServiceScopeFactory.CreateScope does not seem to work in the IJobActivator if Functions is scoped, nor within Functions if it's a singleton. I.e. public static void Main(string[] args) { IServiceCollection serviceCollection = new ServiceCollection(); serviceCollection.AddScoped<Functions>(); //Or serviceCollection.AddSingleton<Functions>(); serviceCollection.AddScoped<TelemetryScopeProvider>(); //... Other scoped

Dagger-android build errror cannot be provided without an @Provides-annotated method

淺唱寂寞╮ 提交于 2019-12-23 05:34:05
问题 I am learning dagger dependency injection(I know i am late to the party, its better to start now). But I am facing below error. Please any help or suggestion could be greatly appreciated. ERROR Log error: [Dagger/MissingBinding] [dagger.android.AndroidInjector.inject(T)] @com.mypackage.di.key.ItemDetail java.lang.Integer cannot be provided without an @Provides-annotated method. public interface ApplicationComponent extends AndroidInjector<RetailShopApplication> { ^ @com.mypackage.di.key

Google Guice and varying injections at runtime

只愿长相守 提交于 2019-12-23 05:32:29
问题 I'd like to vary the injected implementations based on something that's not known until runtime. Specifically, I'd like my app to operate as different versions where the "version" is not determined until a request is executing. Also, the "version" could vary per request. After reading the docs it seems that I could implement a providers in cases where I need to choose an implementation at runtime based on the "version". Additionally, I could roll my own on top of juice. Is implementing a

How to configure dependencies on custom validator with Symfony Components?

不羁的心 提交于 2019-12-23 05:32:27
问题 I am using Symfony Validator and Symfony Service Container in a project, but not the full Symfony Framework. I have written a custom validator that requires some dependencies to be supplied as constructor arguments. The Symfony Documentation describes a method of configuring the validator as service, which I have done successfully. But then it makes of point of using the validator.constraint_validator service tag , which I suspect glues them together. This service tag seems to be specific to

My Play Application's Constructor takes an argument, how do I give a mocked argument at Spec Test?

☆樱花仙子☆ 提交于 2019-12-23 05:11:09
问题 If my play application has something like this: class Foo() extends Bar {} class Application @Inject (f: Foo) extends Controller { def index = Action { OK("Hi, Foo App") } } How do I change my spec test to accept MockedFoo class? @RunWith(classOf[JUnitRunner]) class MockedFoo() extends Bar {} class ApplicationTest(implicit ee: ExecutionEnv) extends Specification { "Sending a GET request to index " should { "Respond with OK " in new WithApplication { //######## Inject MockedFoo val response =

spring: where does `@autowired` look for beans?

流过昼夜 提交于 2019-12-23 04:56:16
问题 I'm having a spring mvc application with two contexts (as declared in my AbstractAnnotationConfigDispatcherServletInitializer subclass) the root context contains models, repositories, etc the mvc context contains the controllers Now, I can inject a repository into a controller, but why? Does the web context also include the beans from the root context (something like @Import ??). The documentation implies they have a parent-child relationship, but by inspecting the web context I don't the

Symfony 4. How to access the service from controller without dependency injection?

只谈情不闲聊 提交于 2019-12-23 04:53:19
问题 I have several services: DieselCaseService, CarloanCaseService LvCaseService. The controller decides which of services to get. $type = $quickCheck["type"]; /** * @var $caseService \App\Service\Cases\CaseInterface */ $type = 'diesel; // for test purposes $caseService = $this->get('case_service.' . $type); The service aliases are declared like this: case_service.diesel: alias: App\Service\Cases\DieselCaseService public: true class DieselCaseService implements CaseInterface { . . . } If I try to

Unity - loadConfiguration, how to resolve only those configured

馋奶兔 提交于 2019-12-23 04:45:22
问题 What I am trying to achieve: Have Unity load the mappings from a configuration file, then in source code resolve the types which were loaded from said configuration file App.Config <register type="NameSpace.ITill, ExampleTightCoupled" mapTo="NameSpace.Till, NameSpace" /> <register type="NameSpace.IAnalyticLogs, NameSpace" mapTo="NameSpace.AnalyticLogs, NameSpace" /> Code IUnityContainer container; container = new UnityContainer(); // Read interface->type mappings from app.config container

Using Autofac with AJAX-enabled WCF Service

馋奶兔 提交于 2019-12-23 04:07:20
问题 I am desperately trying to get this to work. I have used WCF services to do AJAX with JQuery before without any hustle. Now I am using Autofac for DI, and so far it is going quiet good, until I want a WCF service in my UI project to be the base for AJAX. In my regular Webapplication I am using Global.asax 'Application_Start' to register my containers. This is done by calling a Boot() method in my 'MyBootstrapper' project. The Boot() method simply registers all my modules. Now I noticed that