dependency-injection

Understanding dependency injection in AngularJS controllers

白昼怎懂夜的黑 提交于 2019-12-19 03:11:57
问题 Just learning dependency injection, and I think I'm starting to understand it. Please tell me if I'm on the right track... E.g.: Are these two equivalent? /* injection method */ function <controller_name>($scope) {} <controller_name>.$inject = ['$scope']; /* other method */ var app = angular.module('myApp'); app.controller(<controller_name>, function($scope) {}); 回答1: First a little clarification: For dependency injection, it doesn't matter whether you declare a controller using a global

Can you inject dependencies into a constructor of a custom WebViewPage, using an IOC container?

心已入冬 提交于 2019-12-19 02:49:20
问题 In MVC 3, I understand you can create custom WebViewPages. Can you inject dependencies, using constructor injection, via an IOC container? 回答1: There is an expample for view injection in a blog post by Brad Wilson http://bradwilson.typepad.com/blog/2010/07/service-location-pt3-views.html The statements of the others that views allow constructor injection not entirely correct. Yes IDependencyResolver enables creating views that have constructor arguments. But unless you are implementing your

Controller logic vs Service/Business layer logic

十年热恋 提交于 2019-12-19 02:47:41
问题 I am working on an application and am using a Repository-Service-Controller approach for a REST API. I find myself debating between controller logic vs service logic. The service logic deals with business logic, such as calculating a book price, and the controller logic should deal with presentation details. What if part of the business logic of the application is to check the publisher is subscribed to a PremiumService to determine if the book is editable? Would this go in business logic or

Understanding scopes in Dagger 2

霸气de小男生 提交于 2019-12-19 02:47:16
问题 I have an scope-related error in Dagger 2 and I'm trying to understand how I can solve it. I have a CompaniesActivity that shows companies. When the user selects an item, selected company's employees are shown in EmployeesActivity . When the user selects an employee, her detail is shown in EmployeeDetailActivity . class Company { List<Employee> employees; } Class CompaniesViewModel contains the companies and the selected one (or null ): class CompaniesViewModel { List<Company> companies;

MVC 3 Dependency Injection with Ninject 2.2 + Global Action Filter

心已入冬 提交于 2019-12-19 02:45:29
问题 I am trying to use ASP.NET MVC 3 and Ninject 2.2 to inject a logger object into a custom ActionFilterAttribute. I am able to get this to work if I mark each controller with the custom attribute. However I cannot get this to work if I remove the attribute decoration from the controllers and try to use a global action filter. Here is the code: under App_Start - NinjectMVC3.cs using NinjectTest.Abstract; using NinjectTest.Concrete; [assembly: WebActivator.PreApplicationStartMethod(typeof

Inject dependency into DelegatingHandler

…衆ロ難τιáo~ 提交于 2019-12-19 02:03:16
问题 I am new to dependency injection, but happy with Ninject and Ninject.Extensions.Logging to [Inject] my ILogger wherever i need it. However some DelegatingHandlers are spoiling all the fun. public class HttpsHandler : DelegatingHandler { [Inject] public ILogger Logger { get; set; } protected override Task<HttpResponseMessage> SendAsync( HttpRequestMessage request, CancellationToken cancellationToken) { if (!string.Equals(request.RequestUri.Scheme, "https", StringComparison.OrdinalIgnoreCase))

Spring Dependency injection for interfaces

好久不见. 提交于 2019-12-19 00:58:27
问题 Well I've been watching some tutorials about Spring dependency injection as well as MVC, but I still seem to not understand how we can instantiate classes specifically? I mean if for instance I have a variable @Autowired ClassA someObject; How can I make spring create someObject as an Instance of ClassB which would extend ClassA? like someObject = new ClassB(); I don't really understand how it works in spring, does the ContextLoaderListener do it automatically or do we have to create some

ASP.NET Core DependencyResolver

浪子不回头ぞ 提交于 2019-12-18 19:15:10
问题 In ASP.NET MVC 5 is possible to obtain some dependency through DependencyResolver.Current.GetService<T>() . Is there something similar in ASP.NET Core? 回答1: Yes, there is. In ASP.NET Core 1.0.0, the services available within a request from HttpContext are exposed through the RequestServices collection [1] : this.HttpContext.RequestServices You can use the GetService method to retrieve the dependencies by specifying the type of the dependency: this.HttpContext.RequestServices.GetService(typeof

Transactional annotation error

拜拜、爱过 提交于 2019-12-18 18:59:54
问题 When I put " @Transactional(readOnly=false) " annotation in my Service class I get the following error Description: The bean 'studentService' could not be injected as a ' com.student.service.StudentServiceImpl ' because it is a JDK dynamic proxy that implements: com.student.service.StudentService Sample code: @Service("studentService") @Transactional(readOnly=false) public class StudentServiceImpl implements StudentService { } public interface StudentService { } Action: Consider injecting the

PHP MVC: Too many dependencies in controller?

泄露秘密 提交于 2019-12-18 18:23:20
问题 I'm working on a personal HMVC project: No service locators, no global state (like static or global ), no singletons. The model handling is encapsulated in services (service = domain objects + repositories + data mappers). All controllers extend an abstract controller. All project dependencies are injected through Auryn dependency injection container. All needed dependencies are injected in the constructor of the abstract controller. If I want to override this constructor, then I have to pass