dependency-injection

Using PowerMock or How much do you let your tests affect your design? [closed]

若如初见. 提交于 2019-12-20 11:56:18
问题 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 3 years ago . I've been a fan of EasyMock for many years now, and thanks to SO I came across references to PowerMock and it's ability to mock Constructors and static methods, both of which cause problems when retrofitting tests to a legacy codebase. Obviously one of the huge benefits of

Entity Framework : Change connection string at runtime

半腔热情 提交于 2019-12-20 11:37:14
问题 Assuming there is an ASP.NET MVC application that uses Entity Framework 6 with code-first approach and StructureMap as IoC. Also It uses Unit Of Work pattern. Here are the codes : Domain Class public class Product { public int Id { get; set; } public string Name { get; set; } public decimal Price { get; set; } } IUnitOfWork and DbContext : public interface IUnitOfWork { IDbSet<TEntity> Set<TEntity>() where TEntity : class; int SaveChanges(); } public class Sample07Context : DbContext,

Dagger 2: When to use constructor injections and when to use field injections?

不羁的心 提交于 2019-12-20 11:22:41
问题 I was kind of lazy and used to use almost entirely field injections. I was just providing empty constructor, put my @Inject fields I everything was looking nice and simple. However field injection have its trade-offs so I've devised some simple rules that help me to decide when to used field and when to use constructor injections. I will appreciate any feedback if there is mistake in my logic or if you have additional considerations to add. First some clarification in order to be on the same

Generic @Inject'd fields in an abstract superclass

别来无恙 提交于 2019-12-20 11:17:12
问题 Consider a MVP-ish set of types. An abstract Presenter exists, with a View interface: public interface View { //... } public abstract class AbstractPresenter<V extends View> { @Inject V view; //... } Then, lets have a specific concrete presenter subclass, with its view interface and implementation: public interface LoginView extends View { //... } public LoginPresenter extends AbstractPresenter<LoginView> { //... } public class LoginViewImpl implements LoginView { //... } In a Dagger module,

Dagger 2 - what is the purpose of a @Singleton annotation class

試著忘記壹切 提交于 2019-12-20 10:59:34
问题 From the dagger 2 Documentation I noticed that you can have a @Singleton annotated class. What is the purpose of marking a class as @Singleton as I have tried to do this in my code but a singleton object is NOT produced. I'm not clear on what use marking my class with this annotation serves. From the documentation please focus on the following statement: The @Singleton annotation on an injectable class also serves as documentation. It reminds potential maintainers that this class may be

JavaScript DI/IoC equivalents to standard DI patterns for statically typed languages

假装没事ソ 提交于 2019-12-20 10:46:58
问题 .NET and Java both have a slew of DI/IoC containers available to them and each have a number of patterns that I've found very useful at various points in working with them. I'm now at a point where I would like to do equivalent things in JavaScript. As JavaScript is a dynamic language, I don't expect DI/IoC containers to have direct equivalents to all the functionality provided by the containers found in statically typed languages so alternatives to these patterns are welcome. I also expect

How can I resolve the conflict between loose coupling/dependency injection and a rich domain model?

馋奶兔 提交于 2019-12-20 10:44:20
问题 Edit: This is not a conflict on the theoretical level but a conflict on an implementation level. Another Edit: The problem is not having domain models as data-only/DTOs versus richer, more complex object map where Order has OrderItems and some calculateTotal logic. The specific problem is when, for example, that Order needs to grab the latest wholesale prices of the OrderItem from some web service in China (for example). So you have some Spring Service running that allows calls to this

When to use an IOC container?

巧了我就是萌 提交于 2019-12-20 10:29:23
问题 I'm trying to understand when I should use a container versus manually injecting dependencies. If I have an application that uses a 1-2 interfaces and only has 1-2 concrete implementations for each interface, I would lean towards just handling that myself. If I have a small application that uses 2-3 interfaces and each interface has 2-3 concrete implementations, should I use a full-blown container? Would something something simple like this suffice? Basically I'm trying to understand when it

AngularJS - How does the DI system know of the name of the arguments?

强颜欢笑 提交于 2019-12-20 10:06:54
问题 Example straight from the official site: function PhoneListCtrl ($scope, $http) { $http.get('phones/phones.json').success(function(data) { $scope.phones = data; }); $scope.orderProp = 'age'; } The $scope and $http arguments are unique identifiers for locating corresponding AngularJS services inside the DI system. So how does the DI system retrieve the variable name of these arguments, exactly? 回答1: This is the trimmed down version of the way var FN_ARGS = /^function\s*[^\(]*\(\s*([^\)]*)\)/m;

Resource Annotation: No qualifying bean of type [javax.sql.DataSource] is defined: expected single matching bean but found 2

。_饼干妹妹 提交于 2019-12-20 09:59:41
问题 I am using Spring Java Based configuration for configure multiple database with Spring Data. In the configuration file, i am creating two data source for MySQL and MSSQL-Server . When trying to inject dependency to the entity manager using @Resource annotation i am getting following exception: org.springframework.beans.factory.NoUniqueBeanDefinitionException: No qualifying bean of type [javax.sql.DataSource] is defined: expected single matching bean but found 2: mysql_datasource,secure