dependency-injection

How to Test a Play Application that extends a custom trait

99封情书 提交于 2019-12-25 04:11:25
问题 I'm having trouble writing tests for a mixin to my Play application that runs in it's own thread separate from play. I've tried over-writing WithApplication.provideApplication method with no luck. I get an inheriting conflicting methods error. (one from the real app "MyRunnableSystemWrapper", one from my mocked fake mixin called "MyMockedSystemWrapper"). execute(system) runs my system that is tested elsewhere and has sideaffects (connects to networked services, thus failing this test when

Ioc/DI - Why do I have to reference all layers/assemblies in application's entry point?

安稳与你 提交于 2019-12-25 04:09:18
问题 (Related to this question, EF4: Why does proxy creation have to be enabled when lazy loading is enabled?). I'm new to DI, so bear with me. I understand that the container is in charge of instantiating all of my registered types but in order to do so it requires a reference to all of the DLLs in my solution and their references. If I weren't using a DI container, I wouldn't have to reference the EntityFramework library in my MVC3 app, only my business layer, which would reference my DAL/Repo

AutoFac MVC Web API

情到浓时终转凉″ 提交于 2019-12-25 03:12:57
问题 I have a simple AutoFac example working but now want to apply this to my web api project AND have the correct separation between the layers. The issue I am seeing is the standard controller x "does not have a default constructor" but i am stumped so asking for advice.. I am calling RegisterApiControllers as well as RegisterControllers.. this is what I have in my DependencyInjectionContainer public static class DependencyInjectionContainer { public static ContainerBuilder Builder; public

Register custom controller in runtime

北城以北 提交于 2019-12-25 03:05:56
问题 I've some api controller that i want to register at runtime in my mvc application. The controller itself resides into Class Library project and looks like: public class CustomController : ApiController { public string Get() { return "Hello"; } } I've compile that library (gave it a name Injection.dll ), and in my mvc app try to register those controller via Unity.Mvc library container public static class UnityConfig { public static void RegisterComponents() { var container = new

Re-inject CDI bean if some injected property changed

你。 提交于 2019-12-25 03:03:01
问题 I have a bean BeanA with injected property private int url : class BeanA { @Value(${"db.url"}) private String url; private DbConnection connection; } Let us say this Value annotation is similar to Spring Value . During initialization, connection will be initialized by using injected property into url field. And also there is some PostConstruct and PreDestroy methods in BeanA . My question is: is it possible to dynamically reinstantiate BeanA when url property changed. I have mechanism of

Inject into asp.net web api model with autofac

蹲街弑〆低调 提交于 2019-12-25 03:00:13
问题 I want to use IValidatableObject.Validate() to check some aspects of my model against a repository before processing requests. However, with the config below _dalForValidation is never set in on Models.App , in other words the default empty constructor is always being called. private static void ConfigureAutofac() { var builder = new ContainerBuilder(); builder.RegisterApiControllers(Assembly.GetExecutingAssembly()); builder.RegisterType<DataAccessFacade>().As<IDataAccess>()

Ninject in a three tier application

风格不统一 提交于 2019-12-25 02:57:49
问题 I am building a standard three tier app. 1 Console app for front end 2 Business logic layer 3 Data layer The main purpose is to display some customer data from a database table. I'm trying to follow the guide lines in the book "Dependency Injection in .NET" by having no reference from the console to the data layer, and none from the business layer to the data layer. Allowing for easy swapping of the front end and the data layers if needed. Let's say I have a service at the business layer

Field level injection with Gin

扶醉桌前 提交于 2019-12-25 02:34:08
问题 I'm trying to do field-level injection so I don't have to pass "models" when my controllers are instantiated, like, UserController controller = new UserController(/*No need to pass models here*/); However my application throws NullPointerException, here my code: UserController.java public class UserController implements Controller { @Inject private UserModel model; public UserController() { model.doSomething(); // NullPointerException } } ClientGinModule.java public class ClientGinModule

Upgrading a Azure function app to 3.0.0-beta8 and having som DI code break after

元气小坏坏 提交于 2019-12-25 02:28:34
问题 before i updated the dlls Config is off type JobHostConfiguration, any suggestion how to work around this? 回答1: I have created a nuget package for my solution which fixes the issue and also has the ability to use any IoC container: https://github.com/BorisWilhelms/azure-function-dependency-injection 回答2: I fixed this issue by implementing the DI code like in this repo https://github.com/ryanspletzer/DependencyInjectionAzureFunction 来源: https://stackoverflow.com/questions/52150861/upgrading-a

Integrating DI container within domain layer. Domain events

情到浓时终转凉″ 提交于 2019-12-25 01:49:13
问题 Following the article: http://www.udidahan.com/2009/06/14/domain-events-salvation/ we can see that DomainEvents implemantation uses DI container public static IContainer Container { get; set; } and then if(Container != null) { foreach(var handler in Container.ResolveAll<Handles<T>>()) handler.Handle(args); } Should I integrate DI container inside the same assembly I store domain objects or can I externalize/abstract away the Container.ResolveAll<Handles<T>>() ? (In my previous experiences I