dependency-injection

PerRequestLifetimeManager and Task.Factory.StartNew - Dependency Injection with Unity

痞子三分冷 提交于 2020-07-18 07:11:40
问题 How to manage new tasks with PerRequestLifeTimeManager? Should I create another container inside a new task?(I wouldn't like to change PerRequestLifeTimeManager to PerResolveLifetimeManager/HierarchicalLifetimeManager) [HttpPost] public ActionResult UploadFile(FileUploadViewModel viewModel) { var cts = new CancellationTokenSource(); CancellationToken cancellationToken = cts.Token; Task.Factory.StartNew(() => { // _fileService = DependencyResolver.Current.GetService<IFileService>();

PerRequestLifetimeManager and Task.Factory.StartNew - Dependency Injection with Unity

不打扰是莪最后的温柔 提交于 2020-07-18 07:11:30
问题 How to manage new tasks with PerRequestLifeTimeManager? Should I create another container inside a new task?(I wouldn't like to change PerRequestLifeTimeManager to PerResolveLifetimeManager/HierarchicalLifetimeManager) [HttpPost] public ActionResult UploadFile(FileUploadViewModel viewModel) { var cts = new CancellationTokenSource(); CancellationToken cancellationToken = cts.Token; Task.Factory.StartNew(() => { // _fileService = DependencyResolver.Current.GetService<IFileService>();

Autowire a parameterized constructor in spring boot

时光总嘲笑我的痴心妄想 提交于 2020-07-16 07:23:28
问题 I am not able to autowire a bean while passing values in paramterized constructor. How to call the parameterized constructor using SpringBoot? @Component public class MainClass { public void someTask() { AnotherClass obj = new AnotherClass(1, 2); } } //Replace the new AnotherClass(1, 2) using Autowire? @Component public class AnotherClass { private int number,age; public AnotherClass(int number, int age) { super(); this.number = number; this.age = age; } } I want to autowire "AnotherClass"

Autowire a parameterized constructor in spring boot

橙三吉。 提交于 2020-07-16 07:23:19
问题 I am not able to autowire a bean while passing values in paramterized constructor. How to call the parameterized constructor using SpringBoot? @Component public class MainClass { public void someTask() { AnotherClass obj = new AnotherClass(1, 2); } } //Replace the new AnotherClass(1, 2) using Autowire? @Component public class AnotherClass { private int number,age; public AnotherClass(int number, int age) { super(); this.number = number; this.age = age; } } I want to autowire "AnotherClass"

ASP.NET Core DI in a class library?

拥有回忆 提交于 2020-07-08 11:09:06
问题 I have a ASP.NET Core 2.1 project that references a "Data Access Layer" project of typ .NET Core Class Library. The Data Access Layger needs connection string from the appsettings.json in the ASP.NET Core project. I have created a simple container like this : public class DatabaseConnectionString : IDatabaseConnectionString { private readonly string _connectionString; public DatabaseConnectionString(string connectionString) { _connectionString = connectionString; } public string

Symfony2 access private services in tests

一个人想着一个人 提交于 2020-07-06 13:02:06
问题 Currently I'm working on testing some services in Symfony2 and I'm trying to use Guzzle MockPlugin for controlling CURL responses. Symfony version 2.3.8 is used. I've got to an interesting behaviour and I'm not sure if this is a Symfony2 bug or not. I have these services in services.yml: lookup_service_client: class: FOO public: false factory_service: lookup_client_builder factory_method: build lookup_repository_auth_type: class: AuthType arguments: ["@lookup_service_client"] lookup

.NET Core dependency injection - many databases, one DbContext

六眼飞鱼酱① 提交于 2020-06-29 03:50:28
问题 I have an ASP.NET Core application using the DI from Microsoft.Extensions.DependencyInjection . The app connects to a stupid number of databases with an exact same interface, let's say a 100 of them. I want to facade them all with the same DbContext, say ExternalDbContext . The only difference between them is the connection string they're using. I need to instantiate the correct version of the context for a given request. So the chain of resolution would go like this: User makes a request

Creating custom Simple Injector Scope in Web Forms

会有一股神秘感。 提交于 2020-06-28 06:15:40
问题 I have a text box and a button in my Windows forms application. When the start key is pressed with the value written in the textbox, a new Form should be opened with this value. I want to create a scope for each opened form. And when I close the form I want to close the relevant scope. How do I create a custom scope with the simple injector? Here is a simple sample code static class Program { static readonly Container container; static Program() { container = new Container(); container

Factory with parameters in InversifyJS

浪尽此生 提交于 2020-06-27 14:36:10
问题 I'm using InversifyJS with TypeScript. Let's say I have a class which has a mixture of injected and non-injected constructor parameters: @injectable() export class MyClass { constructor( foo: Foo, // This thing isn't injectable @inject(Bar) bar: Bar // This thing is ){ ... } } I would like to inject a factory for this class into some other class and then invoke it with a value for the first parameter. @injectable() export class SomeOtherClass { constructor( @inject("Factory<MyClass>")

Wrapping Angular components which has Parent/Child relationship

╄→尐↘猪︶ㄣ 提交于 2020-06-27 12:22:41
问题 I'm trying to wrap some third-party components with my own components (All of them are Angular 5 components). When using the third-party component (without wrapping them) I have the following code: <div> <xyz-menubar> <a xyzMenubarItem></a> <a xyzMenubarItem></a> </xyz-menubar> </div> My goal is to wrap these components to have the following code: <div> <app-menu> <app-menu-item></app-menu-item> <app-menu-item></app-menu-item> </app-menu> </div> This is how I coded the wrapped components (xyz