dependency-injection

Autofac delegate factories, and passing around container

拜拜、爱过 提交于 2019-12-24 12:01:07
问题 I have a question about delegate factories: autofac docs I understand how they set up the factories but I do not get the resolving part: var shareholdingFactory = container.Resolve<Shareholding.Factory>(); var shareholding = shareholdingFactory.Invoke("ABC", 1234); It looks like you have to pass around the container in order to resolve. Maybe I have to Invoke something with parameters I only know at runtime. How do I do that without passing the container to for example a service method?

Using Dependency Injection in POJO's to inject EJB's

家住魔仙堡 提交于 2019-12-24 11:35:54
问题 Is it possible to inject ejb's into pojo's using the @EJB annotation? If it is, do I have to set up anything special on a JBoss server to make it work? Please let us not discuss the rationale behind doing this - I am just trying to hack some old code to make it work :-) 回答1: Yes, if you can make JBoss create the Pojo for you. Your problem is that you probably call new to create the Pojo and the framework can't intercept this which is why @EJB is ignored. The solution is to use a factory to

Dependency Injection Strict Mode (ng-strict-di) raises error even when array notation is used

↘锁芯ラ 提交于 2019-12-24 11:27:50
问题 I am trying to implement ng-strict-di in Angular to check my code for minification. Even though I am using array notation, it tells me that I am not explicitly defining my dependencies. function(sitesService is not using explicit annotation and cannot be invoked in strict mode Here is my code: angular.module('app').factory('sitesService', ['$q', '$http', 'globalContextService', '$rootScope', '$log', function ($q, $http, globalContextService, $rootScope, $log) { return { ... }; }]); To make

How resolve a dependency with unity passing arguments in the constructor? [duplicate]

纵然是瞬间 提交于 2019-12-24 10:59:25
问题 This question already has answers here : Closed 7 years ago . Possible Duplicate: Can I pass constructor parameters to Unity’s Resolve() method? Constructor Injection in C#/Unity? It is possible to resolve a dependency with unity passing arguments in the constructor of the service to resolve ? If it is how I can do it ? 回答1: Create an InjectionConstructor and pass that to RegisterType() : var unityContainer = new UnityContainer(); ISnuh snuh = new Snuh(); InjectionConstructor

Autofac and MVC integration: Register Type per API Controller

血红的双手。 提交于 2019-12-24 10:59:09
问题 I'm working with .Net 4.5, ASP.NET MVC 5, and the NuGet packages: Autofac 3.5.2 Autofac ASP.NET Web Api 5 Integration 3.0.0-rc1 I have 2 different implementations of an interface: public class MemoryStreamService : IStreamService { ... } public class HttpStreamService : IStreamService { ... } Also another concrete class that uses the interface by constructor injection: public class MainService : IMainService { public MainService(IStreamService streamService) { ... } } And I have 2 ASP.NET Web

PerWebRequest Lifestyle missing in Castle Windsor 3.2

喜夏-厌秋 提交于 2019-12-24 10:56:34
问题 I was using PerWebRequest Lifestyle from Castle Windsor(version 3.0.0.4001). I wanted to update it to the latest version (3.2). In the latest version the, it says does not contain a definition for 'PerWebRequest' and no extension method 'PerWebRequest' accepting a first argument of type 'Castle.MicroKernel.Registration.Lifestyle.LifestyleGroup<.... Below is how I was registering the Component, but with the latest version it throws error: container.Register(Component.For<IUserRepository>()

How should I register this type that has parameterized constructor, in Unity?

若如初见. 提交于 2019-12-24 10:49:50
问题 I am trying to register a type that has a constructor method like: public Foo (int myNumber, IBar bar) {...} I produce instance of IBar via Unity container. How should I regsiter and Resolve the Foo? Regarding to the example below, how can I replace the line new Foo... with a unity register and resolve way? public interface IBar { public void SayNumber(); } public class Bar : IBar { public void SayNumber() { Coonsole.Write("Number : "); } } public interface IFoo { void int GetMyNumberTimesTwo

Ioc/DI - Why do I have to reference all layers/assemblies in application's entry point?

纵然是瞬间 提交于 2019-12-24 10:47:13
问题 (Related to this question, EF4: Why does proxy creation have to be enabled when lazy loading is enabled?). I'm new to DI, so bear with me. I understand that the container is in charge of instantiating all of my registered types but in order to do so it requires a reference to all of the DLLs in my solution and their references. If I weren't using a DI container, I wouldn't have to reference the EntityFramework library in my MVC3 app, only my business layer, which would reference my DAL/Repo

Access IServiceProvider when using generic IHostBuilder

时间秒杀一切 提交于 2019-12-24 10:38:24
问题 I'm using IHostBuilder in a .NET Core 2.1 console application. Main looks like this: public static async Task Main(string[] args) { var hostBuilder = new HostBuilder() .UseServiceProviderFactory(new AutofacServiceProviderFactory()) .ConfigureServices(services => { // Register dependencies // ... // Add the hosted service containing the application flow services.AddHostedService<RoomService>(); }); await hostBuilder.RunConsoleAsync(); } } Before, with IWebHostBuilder , I had the Configure()

AngularJS & D3 : Angular directive for D3 load multiple times

廉价感情. 提交于 2019-12-24 10:36:06
问题 I wrote an angular directive for d3 forced-directed graph. Code is here. I use $log.log("xx"); to debug the code. I realized for some reasone this directive load multiple times. For the mg-controller, the one the directive bond with, I have 2 factories and these two factories are called whenever the controller is initialized. By using $log.log("xx"); I realized when the pay is loaded, the d3 directive at least load 6 times, twice for each factory and twice after. The way I "got around" is