dependency-injection

When can Dependency Injection Containers become too big, and what can I do about it?

穿精又带淫゛_ 提交于 2020-01-12 03:22:25
问题 We all know the why Dependency Injection is awesome because it makes code less coupled, easier to test, and much nicer to read! And then some decide to use a Dependency Injection Container like pimple for PHP to assist with the Dependency Inversion principle in SOLID. So when creating your DiC using pimple, passing it through to the controller, and having all your new objects created in closures that are actually only instantiated when the developer calls $container['object'] , this is great!

Repository pattern with Linq to SQL using IoC, Dependency Injection, Unit of Work

送分小仙女□ 提交于 2020-01-12 02:04:31
问题 There seems to be lots of examples on implementing Repository pattern for Linq to SQL. Most of them featuring IRepository and DI; Some have implemented Unit of Work and some not. I tried to read as most of the results returned by searches on SO and Google on Linq to SQL repository patterns. Nevertheless I've not come across a complete solution yet. From my readings I've implemented a repository pattern as shown below: I'm using DI to register interfaces on which the repositories are depended:

How to inject a Converter in XAML

孤街醉人 提交于 2020-01-12 01:49:06
问题 I have an IValueConverter implemented class and I need it to be injected using my DI container (Ninject). The problem is, in XAML, there's no immediately obvious way to get control over the instantiation of the Converter object. So my XAML contains a line something like this: Source="{Binding Path=CurrentMessage, Converter={StaticResource ImagePathConverter}}" Where, the ImagePathConverter will be created for me. I suppose I could create a "service locator" static class and call it to resolve

How to build a PHP Dependency Injection Container

大兔子大兔子 提交于 2020-01-11 23:44:34
问题 I've recently learned about the advantages of using Dependency Injection (DI) in my PHP application. However, I'm still unsure how to create my container for the dependencies, or whether I should be using DI at all for the online forum that I'm building. The following code is my version of the DI container I have made based on the example I learned from here . class ioc { var $db; var $session; var $user_id; static function newUser(static::$db, static::$user_id) { $user = new User($db, $user

How to build a PHP Dependency Injection Container

余生长醉 提交于 2020-01-11 23:41:11
问题 I've recently learned about the advantages of using Dependency Injection (DI) in my PHP application. However, I'm still unsure how to create my container for the dependencies, or whether I should be using DI at all for the online forum that I'm building. The following code is my version of the DI container I have made based on the example I learned from here . class ioc { var $db; var $session; var $user_id; static function newUser(static::$db, static::$user_id) { $user = new User($db, $user

How to initialize JavaFX controllers with the same model object?

三世轮回 提交于 2020-01-11 15:48:10
问题 Scenario I am creating a GUI where multiple views reference the same model object. What I am Accustom to In Swing, if i want all the views to reference the same model i would pass the model into the constructor. What I am Currently Doing In JavaFX, I am passing the model around by having a setter method in the views/controllers (menubars, split panes, tabs, ...), after each view/controller has been loaded. I find this very tacky and cumbersome. Additionally, I find it won't work because in

Scala Dependency injection with generic class

拈花ヽ惹草 提交于 2020-01-11 13:21:50
问题 Using Guice in Scala, I'm trying to reproduce the following Java code. Foo interface and class declaration: public interface Foo[T] {} public class FooImpl[T] implements Foo[T] {} Guice binding code: bind(Foo.class).to(FooImpl.class); And one use example would be; @Inject public class Bar(Foo<String> foo) {} In scala, my first bet was: bind(classOf[Foo]).to(classOf[FooImpl]) But it's complaining about 'Type Foo takes type parameter' How do I achieve this in scala? Thank you 回答1: Your question

advantage of using applicationcontext.getbean vs @configurable [closed]

北城余情 提交于 2020-01-11 07:45:11
问题 As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance. Closed 8 years ago . what is the advantage of using @configurable compared to on bean that not managed by bean doing di by applicationcontext.getbean ? any

Mocking C++ classes with dependency injection

别等时光非礼了梦想. 提交于 2020-01-11 07:06:48
问题 Say you're testing class A and it has a dependency injection of B which has a dependency injection of C . So you mock B but the only constructor it has requires an injection of C , so do you have to mock C as well and inject the mocked C into the mocked B and only then inject it to A ? What if you have 5 consecutive dependancies? What are the alternatives? I use Google Mock, so a specific answer would help as well. 回答1: Emile has the right idea, you should depend on interfaces not concrete

Winforms - MVP Pattern: Using static ApplicationController to coordinate application?

廉价感情. 提交于 2020-01-11 03:09:28
问题 Background I'm building a two-tiered C# .net application: Tier 1: Winforms client application using the MVP (Model-View-Presenter) design pattern. Tier 2: WebAPI RESTful service sitting on top of Entity Framework and SQL Server. Currently, I have questions relating to the overall architecture of the Winforms client application. I'm new to programming (about a year) but I've made good progress with this application. I want to step back and re-evaluate my current approach to check that I'm