dependency-injection

How to use Entity Framework context with dependency injection?

偶尔善良 提交于 2019-12-21 22:04:14
问题 I'm trying to setup a base Repository class that can use the Entity Framework edmx model context. The problem I'm having is that I need to find an interface that the EF EDMX object context implements so I can pass to the constructor via dependency injections. I've got around this before by using a DataFactory that creates it and stores it in the HttpContext but that kills the ability to unit test. Any help would be appreciated. Thanks! public abstract class BaseRepository<T> where T :

Can IoC and the Managed AddIn Framework (System.AddIn) work together with isolated AppDomains?

孤街浪徒 提交于 2019-12-21 20:59:09
问题 If I use Managed AddIn Framework (System.AddIn) and set it up to use separate AppDomains, can I use a centralized IoC container that is in the primary/default AppDomain? Can the IoC container resolve across the AppDomains? 回答1: I'm going to approach this answer by ignoring the MAF part of the equation, and concentrating on the AppDomain issue. An IoC container could theoretically do what you describe, assuming that the IoC entry point inherits from MarshalByRefObject or is wrapped by a class

DI in Java without annotations?

ぐ巨炮叔叔 提交于 2019-12-21 20:45:52
问题 Is there any way (existing framework) to configure DI in Java without having to add annotations to classes where they "don't belong"? In my research, it looks like to accomplish constructor injection we need to add some annotation to the constructor, like this: @Inject // or @Autowired for Spring Boot public MyInjectedClass(IThing1 thing1, IThing2 thing2) { ... } Spring Boot also suggests adding @Service to implementations in order to register them with DI for injection. Adding these

Make sure that the controller has a parameterless public constructor using Ninject

夙愿已清 提交于 2019-12-21 20:24:11
问题 Here is the issue at hand: While calling my CustomerController through the URL , I get the following exception: ExceptionMessage: An error occurred when trying to create a controller of type 'CustomerController'. Make sure that the controller has a parameterless public constructor. I am using the following url's: http://localhost:55555/api/Customer/ http://localhost:55555/api/Customer/8 Please note: The /api/Customer/ call were working before I refactored the logic into a business class and

Unity 3 Configuration By Convention not finding Types in Web Project

人走茶凉 提交于 2019-12-21 18:06:22
问题 I am trying to get this convention configuration working but I am having a problem in my ASP.NET MVC5 Project.. I have added the following in my Application_Start method and hooked it up to DependencyResolver public static IUnityContainer CreateContainer() { IUnityContainer container = new UnityContainer(); container.RegisterTypes( AllClasses.FromAssembliesInBasePath(), WithMappings.FromAllInterfaces, WithName.Default, WithLifetime.ContainerControlled); return container; } But it fails to

C# Object construction outside the constructor

别来无恙 提交于 2019-12-21 17:53:27
问题 When it comes to designing classes and "communication" between them, I always try to design them in such way that all object construction and composing take place in object constructor. I don't like the idea of object construction and composition taking place from outside, like other objects setting properties and calling methods on my object to initialize it. This especially gets ugly when multiple object try to do thisto your object and you never know in what order your props\methods will

How can I replace Activity scoped dependencies with mocks using Dagger2

删除回忆录丶 提交于 2019-12-21 17:49:14
问题 I have a scoped dependency in my Activity and I want to test that activity with some mocks. I have read about different approach that suggest to replace Application component with a test component during the test, but what I want is to replace the Activity component. For example, I want to test the Activity against mock presenter in my MVP setup. I believe that replacing component by calling setComponent() on Activity will not work, because Activity dependencies already injected via field

How to do dependency injection inside ASP.NET MVC's RegisterGlobalFilters method

蹲街弑〆低调 提交于 2019-12-21 17:43:20
问题 I am still a bit new to using IOC containers and I'm struggling a bit. I am using ASP.NET MVC 5.2 with Ninject.MVC3. I have an exception filter that basically hands off to a log service: public class ExceptionLoggerFilter : IExceptionFilter { private readonly ILogService _logService; public ExceptionLoggerFilter(ILogService logService) { _logService = logService; } public void OnException(ExceptionContext filterContext) { _logService.LogError(filterContext.Exception); } } I would like to use

Dependency Injection and Unit of Work pattern

大憨熊 提交于 2019-12-21 17:30:18
问题 I have a dilemma. I've used DI (read: factory) to provide core components for a homebrew ORM. The container provides database connections, DAO's,Mappers and their resultant Domain Objects on request. Here's a basic outline of the Mappers and Domain Object classes class Mapper{ public function __constructor($DAO){ $this->DAO = $DAO; } public function load($id){ if(isset(Monitor::members[$id]){ return Monitor::members[$id]; $values = $this->DAO->selectStmt($id); //field mapping process omitted

Custom MembershipProvider: No parameterless constructor defined for this object

落花浮王杯 提交于 2019-12-21 12:38:15
问题 I have a custom MembershipProvider class that inherits from MembershipProvider that takes two parameters: public class CustomMembershipProvider : MembershipProvider { private readonly ISecurityRepository _securityRepository; private readonly IUserRepository _userRepository; public CustomMembershipProvider(ISecurityRepository securityRepository, IUserRepository userRepository) { ... } public override MembershipUser GetUser(string username, bool userIsOnline) { ... } ... etc } The config file