dependency-injection

Entity Framework 4 DB-First Dependency Injection?

孤者浪人 提交于 2019-12-21 05:25:09
问题 I prefer creating my own DB, setting up indexes, unique constraints etc. Generating the domain model from the database is a cinch with the edmx Entity Framework designer. Now I'm interested in setting up some repositories an using Dependency Injection. I've looked at some articles and posts on StackOverflow and seem to focus on the code-first approach. It is pretty slick how you can create a generic repository to handle the CRUD and use Dependency Injection to choose the implementation

Castle Windsor/DelegatingHandler/IPrincipal Dependency Injection (DI)/Inversion of Control (IoC) in ASP.NET Web API

99封情书 提交于 2019-12-21 05:23:16
问题 I decided to clean this post up and I posted a sample project at ge.tt/3EwoZEd/v/0?c Spent around 30 hours on this already and still can't figure it out... help would be really appreciated! I have an ASP.NET Web API solution that uses this code: http://www.piotrwalat.net/basic-http-authentication-in-asp-net-web-api-using-message-handlers/ to implement "Basic HTTP authentication in ASP.NET Web API using Message Handlers". I'm new to IoC/DI and I'm trying to get this to work with Castle Windsor

Dependency Injection in PHP 5.3

烂漫一生 提交于 2019-12-21 05:22:08
问题 I am trying to tidy up an application, and have manually been doing Constructor Dependency Injection for a while. This is a bit tedious, and I would like to start utilizing a Dependency Injection Container instead. I am looking for an actively developed and maintained DI container. I have found Crafty as an alternative, which can wire together dependencies with XML, YAML, Arrays or programatically. The DI container should not be tightly coupled with a full blown framework, we are looking for

How to avoid dependency injection in Scala?

孤人 提交于 2019-12-21 05:18:13
问题 I read Dependency Injection Without the Gymnastics PDF which indicates there's no need for any fancy DI framework, but it's beyond my grasp (at least without concrete examples). I'll try watching Dependency Injection Without the Gymnastics and Dead Simple Dependency Injection when I have a chance. Using Guice in Java, if A depends on both B and C and both B and C depend on D, one would have something like: public class A { @Inject public A(B b, C c) { this.b = b; this.c = c; } } public class

Why the Service Locator is a Anti-Pattern in the following example?

时光毁灭记忆、已成空白 提交于 2019-12-21 05:16:22
问题 I have a MVC application with a Domain Model well defined, with entities, repositories and a service layer. To avoid having to instantiate my service classes inside my controllers, and thus, mess my controllers with logic that does not suit they, I created a helper that acts as a sort of Service Locator, but after reading a bit, I realized that many devs: http://blog.tfnico.com/2011/04/dreaded-service-locator-pattern.html http://blog.ploeh.dk/2010/02/03/ServiceLocatorIsAnAntiPattern.aspx http

How to Avoid Coupling with an IoC Container

二次信任 提交于 2019-12-21 05:03:29
问题 I'm in the process of developing an extensible framework using DI and IoC. Users must be able override existing functionality within the framework by dropping their own implementations into the container. How can I allow users to do this without requiring them to know which IoC container I am using? My current half-way solution is to structure my assemblies as follows: 1) Define abstract assemblies containing only interfaces. 2) Define concrete assemblies which implement these interfaces.

Injecting application context in library module with Dagger 2

喜夏-厌秋 提交于 2019-12-21 04:46:08
问题 I'm building an app with some features: a ContentProvider a SyncAdapter, a Job service and related persistence logic. On top on these there are the Activities with the UI. I'm trying to put all said features in a separate library module, because in theory their logic is stand-alone and would be reusable by any application. Now comes Dagger2. The first node (main Component) of my library's dependency graph does need to provide Context, and this Context has to be injected from the Application,

could not found bean for MongoRepository (Spring Boot)

我的梦境 提交于 2019-12-21 04:17:21
问题 I am using spring boot and MongoDB . Spring version : 4.3.9 Spring boot version : 1.5.4 I am creating a repository which implements MongoRepository interface , like below import org.springframework.data.mongodb.repository.MongoRepository; import org.springframework.stereotype.Repository; @Repository public interface HotelRepository extends MongoRepository<Hotel,String> { } But, whenever I am adding a dependency to HotelRepository compiler giving the error Field hotelRepository in com.demo

Why prefer template method over dependency injection?

不羁岁月 提交于 2019-12-21 04:12:19
问题 I've been reading Design Patterns, by Gamma et al. I have a question concerning the Template Method as compared to Dependency Injection. With Template Method, you "template" classes with policies that provide alternatives for needed actions or calculations. So rather than choosing one policy from several alternatives and coding that policy into the class, you allow the user of the class to specify the alternative they want to use. It all sounds very reasonable to me. But I hit a bit of a

How to combine designable components with dependency injection

感情迁移 提交于 2019-12-21 04:07:05
问题 When creating a designable .NET component, you are required to provide a default constructor. From the IComponent documentation: To be a component, a class must implement the IComponent interface and provide a basic constructor that requires no parameters or a single parameter of type IContainer. This makes it impossible to do dependency injection via constructor arguments. (Extra constructors could be provided, but the designer would ignore them.) Some alternatives we're considering: Service