dependency-injection

Circular dependency - Injecting objects that are directly depended on each other

这一生的挚爱 提交于 2019-12-30 08:14:41
问题 I have used Dice PHP DI container for quite a while and it seems the best in terms of simplicity of injecting dependencies. From Dice Documentation: class A { public $b; public function __construct(B $b) { $this->b = $b; } } class B { } $dice = new \Dice\Dice; $a = $dice->create('A'); var_dump($a->b); //B object However, when you have to use objects that are directly dependent on each other, the finall result is server error, because of the infinite loop . Example: class A { public $b; public

How to make AutoFac use same instance of nested dependency per top-level object? (SignalR dependency injection per hub)

 ̄綄美尐妖づ 提交于 2019-12-30 07:34:08
问题 I am trying to set up my AutoFac registration in such a way that this test passes: [Test] public void Autofac_registration_test() { // Given var builder = new ContainerBuilder(); RegisterServices(builder); var container = builder.Build(); // When var firstHub = container.Resolve<Hub>(); var secondHub = container.Resolve<Hub>(); // Then firstHub.Should().NotBe(secondHub); firstHub.FooRepo.Context.Should().Be(firstHub.BarRepo.Context); firstHub.FooRepo.Context.Should().NotBe(secondHub.FooRepo

What DI/IoC framework should I learn next? [closed]

怎甘沉沦 提交于 2019-12-30 07:33:07
问题 Closed . This question is opinion-based. It is not currently accepting answers. Want to improve this question? Update the question so it can be answered with facts and citations by editing this post. Closed 5 years ago . I've used Spring and Spring.NET quite a bit, but I would like to see what else is out there. Can anyone recommend a good Java or .NET framework that I could try to learn? 回答1: Here is a list of IoC containers from the good Mr. Hanselman... 回答2: Castle Windsor is very popular,

What DI/IoC framework should I learn next? [closed]

不羁岁月 提交于 2019-12-30 07:32:02
问题 Closed . This question is opinion-based. It is not currently accepting answers. Want to improve this question? Update the question so it can be answered with facts and citations by editing this post. Closed 5 years ago . I've used Spring and Spring.NET quite a bit, but I would like to see what else is out there. Can anyone recommend a good Java or .NET framework that I could try to learn? 回答1: Here is a list of IoC containers from the good Mr. Hanselman... 回答2: Castle Windsor is very popular,

Ninject - dynamically specifying a connection string based on a sub domain

最后都变了- 提交于 2019-12-30 07:16:22
问题 I'm trying to specify a connection string dynamically based of the url using ninject. I'm using the ninject.mvc nuget package that uses the webActivator. My code is as follows: my injection: kernel.Bind<IUnitOfWork>().To<UnitOfWork>() .WithConstructorArgument("connectionString", MvcApplication.GetConnectionStringName()); my global.asax private static HttpContext _context; public static string GetConnectionStringName() { var subDomain = String.Empty; if (_context != null) { subDomain =

Passing Services using Dependency Injection and Factory Pattern in ASP.NET

最后都变了- 提交于 2019-12-30 05:05:10
问题 I am using ASP.NET Core, I know that such Logging mechanism is already provided by the framework, but using this to illustrate my problem. I am using kind of Factory pattern to build the Logger class, since I don't know the type of logging (because it is stored in DB). The ILogger Contract Log(string msg) Then LoggerFactory will return an ILogger after creating a Logger based on param passed from DB: public class LoggerFactory { public static Contracts.ILogger BuildLogger(LogType type) {

Getting autofac to work with mvc6 beta5

拜拜、爱过 提交于 2019-12-30 04:34:09
问题 I am trying to get autofac working with an mvc6 application I am working on. I found this blog article however it seems to be a little dated. It looks like its using the beta3 bits I am using this clr version 1.0.0-beta5-11911 My project has these 2 references "Autofac": "4.0.0-alpha2", "Autofac.Dnx": "4.0.0-alpha2", Within the article is talks about how to modify the startup.cs // Create the Autofac container builder. var builder = new Autofac.ContainerBuilder(); // Add any Autofac modules

How to $inject into Angular class w/ES6

孤街醉人 提交于 2019-12-30 04:10:45
问题 Using Angular 1.4 with ES6/7 and Babel, I can successfully inject parameters into a class named Controller with this code after the class block: class Controller { constructor($scope, $state, $window) {...} ... } Controller.$inject = ["$scope", "$state", "$window"] However, it would be cleaner to see the inject parameters right above the constructor. I've seen other people use static $inject, but I get an error. Here's what I'm attempting: class Controller { static $inject = ["$scope", "

What is the Spring DI equivalent of CDI's InjectionPoint?

烈酒焚心 提交于 2019-12-30 04:06:34
问题 I would like to create a Spring's bean producer method which is aware who invoked it, so I've started with the following code: @Configuration public class LoggerProvider { @Bean @Scope("prototype") public Logger produceLogger() { // get known WHAT bean/component invoked this producer Class<?> clazz = ... return LoggerFactory.getLogger(clazz); } } How can I get the information who wants to get the bean injected? I'm looking for some equivalent of CDI's InjectionPoint in Spring world. 回答1: As

Passing state as parameter to a ring handler?

余生颓废 提交于 2019-12-30 04:01:07
问题 How does one inject state into ring handlers most conveniently (without using global vars)? Here is an example: (defroutes main-routes (GET "/api/fu" [] (rest-of-the-app the-state))) (def app (-> (handler/api main-routes))) I would like to get the-state into the compojure handler for main-routes . The state might be something like a map created with: (defn create-app-state [] {:db (connect-to-db) :log (create-log)}) In a non ring application I would create the state in a main function and