dependency-injection

Injecting service into domain object once again

喜你入骨 提交于 2020-01-03 21:03:09
问题 I've got specific domain that operates on a geographical data. I'm implementing this project in TypeScript and NodeJS and have following classes: Point - value object containing latitude and longitude Area - value object containing set of points as a shape definition Sector - entity (it's not persisted, but it's mutable) - containing area and set of points that lie inside it Now I need implement a method named isPointInside(point: Point) that calculates whether provided point fits inside of

How to inject dependency to static class

最后都变了- 提交于 2020-01-03 17:46:07
问题 I've been making simple logger class with DI but I have some problem and question. There is a problem. If I make a logger class with DI. I should use it like this whenever I use it. var logger = new LogService(new FileLogger()); logger.WriteLine("message"); I want to make it to static class, but there is no way to inject dependency by constructor in static class. So, I change it like this. public static class LogService() { private static readonly ILoggable _logger; static LogService() {

Load external environment parameters in Symfony 3.2 using env() at runtime return unresolved values

做~自己de王妃 提交于 2020-01-03 17:33:22
问题 I have a parameters file in an application using symfony 3.2 console, config and YAML component , and i try to set external Parameters from environment variable in the Service Container parameters. I create container builder. $container = new ContainerBuilder(); Am using file locator to locate resources : $container = new ContainerBuilder(); Loader resolver to load resources LoaderResolver(); And using load method : $this->load('parameters.yml'); parameters.yml file: parameters: database:

Load external environment parameters in Symfony 3.2 using env() at runtime return unresolved values

好久不见. 提交于 2020-01-03 17:32:22
问题 I have a parameters file in an application using symfony 3.2 console, config and YAML component , and i try to set external Parameters from environment variable in the Service Container parameters. I create container builder. $container = new ContainerBuilder(); Am using file locator to locate resources : $container = new ContainerBuilder(); Loader resolver to load resources LoaderResolver(); And using load method : $this->load('parameters.yml'); parameters.yml file: parameters: database:

Autofac, IDisposable and manually calling .Resolve in certain circumstances

混江龙づ霸主 提交于 2020-01-03 17:04:50
问题 I've posted a general guideline question when it comes to IDisposable objects and using Autofac here: Dependency Injection and IDisposable. Unfortunately, I did not account for one particular scenario in our project and it's really a separate question that stands on its own, so will ask it here: I have a Repository object that manages the life of a session object inside it. Thus, Repository object is IDisposable and destroys session (Repository is injected with a factory delegate at

CastleWindsor LifeStyle.PerWebRequest behaves like singleton

大憨熊 提交于 2020-01-03 17:04:27
问题 I am trying to create a UserService that I can inject in my classes, that will hold the user currently logged in to my system. I am using CastleWindsor as my container. Now my problem is that I am trying to make my UserService disposable, so that the databaseconnection fetching the user on creating will also be disposed when the object is destroyed. I added the following setup in my Global.asax.cs: private static void BootstrapContainer() { _container = new WindsorContainer().Install

In Kodein dependency injection, how can you inject instances of Kodein itself into instances?

时光毁灭记忆、已成空白 提交于 2020-01-03 16:56:17
问题 In Kodein, I have modules imported into a parent module, and sometimes the classes need an instance of Kodein so they can do injection themselves later. The problem is this code: val parentModule = Kodein { import(SomeService.module) } Where SomeService.module needs the Kodein instance for later, but Kodein isn't yet created. Passing it later into the module seems like a bad idea. In Kodein 3.x I see there is the kodein-conf module that has a global instance, but I want to avoid the global.

OSGi/Felix Declarative Services: How to filter the services to be bound?

依然范特西╮ 提交于 2020-01-03 15:32:17
问题 I am using Apache Felix and its Declarative Services (SCR) to wire the service dependencies between bundles. For example, if I need access to a java.util.Dictionary I can say the following to have SCR provide one: /** * @scr.reference name=properties interface=java.util.Dictionary */ protected void bindProperties(Dictionary d) { } protected void unbindProperties(Dictionary d) { } Now, I have more than one Dictionary service available, and I want to filter them using the "name" service

Register all the services at once using Default DI Container from ASP.NET 5 similar to Autofac

两盒软妹~` 提交于 2020-01-03 14:28:15
问题 With ASP.NET 5, there's already a DI shipped as default and it looks interesting. I have been using Autofac with MVC 5 which has the option to register all the assembly at once. Here is a sample code that register all the classes that ends with "Service" in Autofac. // Autofac Configuration for API var builder = new ContainerBuilder(); builder.RegisterModule(new ServiceModule()); ... ... builder.RegisterAssemblyTypes(Assembly.Load("IMS.Service")) .Where(t => t.Name.EndsWith("Service"))

Register all the services at once using Default DI Container from ASP.NET 5 similar to Autofac

梦想的初衷 提交于 2020-01-03 14:28:08
问题 With ASP.NET 5, there's already a DI shipped as default and it looks interesting. I have been using Autofac with MVC 5 which has the option to register all the assembly at once. Here is a sample code that register all the classes that ends with "Service" in Autofac. // Autofac Configuration for API var builder = new ContainerBuilder(); builder.RegisterModule(new ServiceModule()); ... ... builder.RegisterAssemblyTypes(Assembly.Load("IMS.Service")) .Where(t => t.Name.EndsWith("Service"))