dependency-injection

Dagger 2 Third part Injection Android

蓝咒 提交于 2019-12-14 01:04:55
问题 Hi im trying to figure out how to do a clean third party injection. I want to inject Otto bus properly into my services and activities. Iv seen that you can use inject on constructor, but since I dont have any constructor with Android, i wonder how I can then inject my bus. Iv created a module which provides a new instance of the bus. Iv also created a component which has an interface for the Bus object. But how can I get this injected and where should I initiate my graph? Since the

Share lifetime managers between types in Unity?

别说谁变了你拦得住时间么 提交于 2019-12-14 00:46:42
问题 The examples I've seen in the Unity documentation have you specifying the lifetime manager by putting new LifetimeManager() inline. So I have this code: container.RegisterType<ApplicationDbContext>(new PerRequestLifetimeManager()); container.RegisterType<IUserStore<ApplicationUser>, UserStore<ApplicationUser>>(new PerRequestLifetimeManager(), new InjectionConstructor(typeof (ApplicationDbContext))); container.RegisterType<UserManager<ApplicationUser>>(new PerRequestLifetimeManager()); Fine,

Domain Driven Design issue regarding repository

◇◆丶佛笑我妖孽 提交于 2019-12-14 00:26:01
问题 I am trying to implement the DDD so I have created the following classes - User [the domain model] - UserRepository [a central factory to manage the object(s)] - UserMapper + UserDbTable [A Mapper to map application functionality and provide the CRUD implementation] My first question is that when a model needs to communicate with the persistent layer should it contact the Repository or the mapper? Personally I am thinking that it should ask the repository which will contact the mapper and

Need some help to understand Anotations - Spring annotations

自作多情 提交于 2019-12-14 00:24:01
问题 I am trying to learn Spring and Hibernate and i am really struggling to understand Annotations and how they work. Most of the example i am seeing on the Internet are annotation based examples so i need to understand how the annotations work first before i can learn Spring or Hibernate I have an idea of what they are and what they are used for. I know that they replace the xml configuration. I.e. You can configure beans directly within Java code using annotations. What i dont understand is how

Angular 2 components tree

浪子不回头ぞ 提交于 2019-12-13 22:24:24
问题 I'm developing my first application with Angular 2 and I have installed Augury plugin for Google Chrome, in order to help me debug the code. Here's the components tree and graph: This is the HTML template of my custom component (DocumentsList): <div class="container-fluid" style="margin-top: 10px"> <div class="table-row header"> <div class="column index">#</div> <div class="wrapper attributes"> <div class="wrapper title-comment-module-reporter"> <div class="wrapper title-comment"> <div class=

Autofac and DI for ValidationAttribute

假如想象 提交于 2019-12-13 22:01:07
问题 I have the following validation attribute class: public class ZipCodeValidationAttribute : ValidationAttribute { private readonly IValidationRepository _repository; public override bool IsValid(object value) { var repository = _repository; return repository.IsPostalCodeValid((string) value); } } To test I am trying to use Autofac as my IOC and use property injection. I've set up the test as follows: [TestMethod] public void When_PostalCodeAttribute_Given_ValidPostalCode_Then_SystemReturnsTrue

Conditional dependency resolution in ASP.NET MVC using castle windsor

99封情书 提交于 2019-12-13 19:38:12
问题 I am trying to solve this case in our code where I need to resolve the dependency at runtime based on a specific condition, such as if certain query string value exist or not. Let say I have a controller AuthenticationController and I have authentication service having two flavours of it. public class AuthenticationController { private readonly IAuthenticationService authenticationService; public AuthenticationController(IAuthenticationService authenticationService) { this

Retrofit unit tests to large solution, IOC, Moq

半世苍凉 提交于 2019-12-13 19:23:23
问题 I am in the process of retrofitting unit tests for a asp.net solution written in VB.Net and c#. The unit tests need to verify the current functionality and act as a check for future breaking changes. The solution comprises of: 1 MVC web project written in vb.net (don't ask, it's a legacy thing) 10 other supporting projects each containing logically grouped functionality written in C#, each project contains repositories and DAL All the classes are tightly coupled as there is no inversion of

Ninject cyclic dependency - already using property injection

孤者浪人 提交于 2019-12-13 19:17:26
问题 I'm having a problem with a cyclic dependency in a project using dependency injection. In looking around, it seems that the only way to avoid it, other than restructuring (I did some of that too), is to use property injection. I tried this, and it doesn't seem to help, but I'm not sure why. Here is the path that's causing issues. Activation path: 6) Injection of dependency IUserRepository into property UserRepository of type ModelFactory{UserRole} 5) Injection of dependency IUserRoleFactory

use injected implementation in constructor [duplicate]

对着背影说爱祢 提交于 2019-12-13 19:06:20
问题 This question already has answers here : Why shouldn't I call my dependencies from within the constructor? (2 answers) Closed 5 years ago . Sorry about the ambiguous title, but I wasn't sure how to phrase it. I am looking for any thoughts on whether the following would be a poor usage of an injected object. I have an IOC container set up in my application (I am using Unity, but I don't think that really matters for this). I was wondering if it is bad practice or if there is any catch to