dependency-injection

Dependency injection when the class created also needs runtime values?

空扰寡人 提交于 2019-12-30 03:27:07
问题 Assume you divide up your systems in Value objects and Services objects (as suggested in "Growing Object-Oriented Software, Guided by Tests". Misko Hevery calls these "newables" and "injectables". What happens when one of your value objects suddenly needs to access a service to implement it's methods? Let's say you have a nice simple Value object. It's immutable, holds a few bits of information and that's about it. Let's say we use it something like this: CreditCard card = new CreditCard(

Inversion of Control with .net

扶醉桌前 提交于 2019-12-30 03:24:05
问题 It's rare that I hear someone using Inversion of Control (Ioc) principle with .Net. I have some friends that work with Java that use a lot more Ioc with Spring and PicoContainer. I understand the principle of removing dependencies from your code... but I have a doubt that it's so much better. Why do .Net programmers not use (or use less) those types of frameworks? If you do, do you really find a positive effect in the long term? 回答1: Lots of people use IOC in .NET, and there are several

Inject ASP.NET MVC Controller property into service layer dependency?

柔情痞子 提交于 2019-12-30 03:18:09
问题 I am using an approach similar to the one in this ASP.NET MVC tutorial where you pass a wrapper around a controller's ModelState collection into a validation class so that the controller can access error information. Here is a cooked up example: interface IProductValidator { void Validate(Product item); } class ProductValidator { // constructor public ProductValidator(ModelStateWrapper validationDictionary) { } } interface IProductService { void AddProduct(); } public class ProductService :

What is the benefit of AngularJS Strict DI mode?

流过昼夜 提交于 2019-12-30 02:43:13
问题 Recently I come across with AngularJS Strict DI mode. What is the purpose & benefit of using it? Will we gain significant performance improvement by using it especially on mobile devices? I try to apply it to my code and I did not do any annotation when writing the code. However, I have my code to be minify, and ng-annotate during build. But why is that after I add Strict DI mode to my code I still get the error saying "Explicit annotation required"? 回答1: Strict DI Mode basically throws

laravel - dependency injection and the IoC Container

南楼画角 提交于 2019-12-30 02:28:09
问题 I'm trying to wrap my head around dependency injection and the IoC container and i'm using my UserController as an example. I'm defining what the UserController depends on in its constructor and then am binding those objects to it using App::bind(). If i'm using the Input::get() facade/method/thing am i not taking advantage of the Request object i just injected into it? Should i be using the following code instead, now that the Request object is injected or doesInput::get() resolve to the

WELD-001408: Unsatisfied dependencies for type Customer with qualifiers @Default

那年仲夏 提交于 2019-12-30 01:34:33
问题 I'm a Java EE-newbie. I want to test JSF and therefore made a simple program but can not deploy it. I get the following error message: cannot Deploy onlineshop-war deploy is failing=Error occurred during deployment: Exception while loading the app : CDI deployment failure:WELD-001408: Unsatisfied dependencies for type Customer with qualifiers @Default at injection point [BackedAnnotatedField] @Inject private de.java2enterprise.onlineshop.RegisterController.customer at de.java2enterprise

Multiple Interface injection with castle windsor

瘦欲@ 提交于 2019-12-30 00:39:10
问题 How can you get castle Windsor to choose the right implantation of a interface at run time when you have multiple implementations in the container. For example lets say i have a simple interface called IExamCalc that does calculations to work out how someone did in that exam. No we have several implementation of this like bellow for example, public interface IExamCalc { int CalculateMark(ExamAnswers examAnswers) } public class WritenExam : IExamCalc { public int CalculateMark(ExamAnswers

ASP.Net Core MVC Dependency Injection not working

南楼画角 提交于 2019-12-30 00:28:14
问题 I am trying to inject a interface into to my HomeController and I am getting this error: InvalidOperationException: Unable to resolve service for type 'Microsoft.Extensions.Configuration.IConfiguration' while attempting to activate My Startup class is as follows: public Startup(IApplicationEnvironment appEnv) { var builder = new ConfigurationBuilder() .SetBasePath(appEnv.ApplicationBasePath) .AddEnvironmentVariables() .AddJsonFile("appsettings.json"); Configuration = builder.Build(); } public

DbContext for background tasks via Dependency Injection

老子叫甜甜 提交于 2019-12-29 18:42:52
问题 I am probably not thinking in the right direction. I am fairly new to Dependency Injection and ASP.Net Core. I have a ASP.Net core website, and one of the tasks is to import data from an excel sheet to a database that a user will upload. The excel sheets can be huge and the data transformation tasks are time taking, hence I wish to perform them in the background. i.e. The user will upload the sheet, the response will be sent immediately and the background job/thread will import the data. I am

Symfony2: Inject current user in Service

为君一笑 提交于 2019-12-29 18:35:06
问题 I am trying to inject the currently logged in user into a service. My goal is to extend some twig functionality to output it based on user preferences. In this example I want to output any date function using the user specific Timezone. There doesn't seem to be any way to inject the current user into a service, which seems really odd to me. When injecting the security context, it doesn't have a token even if the user is logged in I am using FOS user bundle. services: ... twigdate.listener