dependency-injection

Using dependency injection in a non-controller class?

对着背影说爱祢 提交于 2019-12-13 15:21:19
问题 I have a DocumentRenderer class, which calls an external API. The DocumentRenderer requires an AccessKey, which is stored in my appsettings.json config file. I want a newly instantiated DocumentRenderer object to, by default, use the AccessKey specified in the config file. However, I can't figure out how to achieve this outside of startup.cs. (I'm using ASP.NET Core) Here's what I've tried so far: Added DocumentRenderer to appsettings.json: "DocumentRenderer": { "AccessKey": "<key>",

Getting Cannot resolve reference Local ejb-ref not implementing parent interface

本秂侑毒 提交于 2019-12-13 15:09:58
问题 I'm trying to figure out why I need to implement both of these interfaces in order to avoid deployment issues. Java Code ExamplePlanAssembler.java @Local public interface ExamplePlanAssembler { ExamplePlan toBO(ExamplePlanEntity entity); } ExtendedExamplePlanAssembler.java @Local public interface ExtendedExamplePlanAssembler extends ExamplePlanAssembler{ ExtExamplePlan toBO(ExamplePlanEntity entity, ExtExamplePlanEntity extEntity); } ExtendedExamplePlanAssemblerImpl.java @Stateless public

Runtime services no longer get injected into DNX console app (RC1)

自闭症网瘾萝莉.ら 提交于 2019-12-13 14:27:49
问题 I used to be able to inject runtime services like IApplicationEnvironment into the constructor of the Pogram class of a DNX console application. However, using the latest CI build of RC1, the services no longer get injected: public Program(IApplicationEnvironment env) { if (env == null) { // env is null. throw new ArgumentNullException(nameof(env)); } } 回答1: The DNX platform wants to be compatible with regular Program.Main entry points. Therefore they removed dependency injection into the

StructureMap: Creation as Transient (per request) not working

ⅰ亾dé卋堺 提交于 2019-12-13 14:05:15
问题 I'm trying to solve a IoC problem, that seemed easy at first, but turned out to be a pain in the ass:-P I have a heavy weight main class, which must be initialized only once, so it's marked as Singleton. However this class uses a subclass which must be created once for each request, so it's marked as Transient: public class MyRegistry : Registry { public MyRegistry() { For<IMainClass>() .Singleton() .Use(ctx => new MainClass(() => ctx.GetInstance<ISubClass>())); For<ISubClass>() .Transient()

Many-To-Many Generic Update Method with Entity Framework 6

北慕城南 提交于 2019-12-13 14:03:28
问题 I have a generic Update method for Entity Framework in an abstract DatabaseOperations<T,U> class: public virtual void Update(T updatedObject, int key) { if (updatedObject == null) { return; } using (var databaseContext = new U()) { databaseContext.Database.Log = Console.Write; T foundEntity = databaseContext.Set<T>().Find(key); databaseContext.Entry(foundEntity).CurrentValues.SetValues(updatedObject); databaseContext.SaveChanges(); } } However, this does not handle many-to-many relationships.

Ninject - Kernel in static class?

点点圈 提交于 2019-12-13 13:49:11
问题 Is it right at all to "wrap" a StandardKernel with the required NinjectModule s in a static class in a separate, shared library, and use that same library whenever injection is needed (instead of instantiating a new kernel everytime)? Edit: I am trying to use Ninject from within the WCF service I am developing at the moment. (Please bear with me if what I am saying is completely rubish since I just started learning about DI and IoC containers) 回答1: See https://github.com/ninject/ninject

how to write libraries without forcing users to use the library's IOC container

帅比萌擦擦* 提交于 2019-12-13 12:26:21
问题 The short question is: Given a library warrants using a particular IOC container for its internals, when an application consumes that library, given the app warrants using an IOC container for wiring its dependencies, given if the the two containers are different, how can they play well together? The scenario is, the application has classes defined that depend on types from the library. So when the application container attempts to build such a class, it needs to know how to resolve the type

OOP Dependencies: Dependency Injection vs. Registry

心已入冬 提交于 2019-12-13 12:17:35
问题 I know some OOP and have read this and that, but am not a hardcore OOP guy and have no formal training and can't rattle off why something should use dependency injection or not, and may not be able to identify all dependencies in a design, hence my question. Answering a question here on SO (Using a object in methods of other objects) I started to doubt myself. As far as dependencies, is one of these better or worse or both acceptable? Any design limitations? I have read and understand both

ControllerFactory for specific portable area

心不动则不痛 提交于 2019-12-13 11:51:10
问题 My main ASP.NET MVC composite application uses a global Unity container to register types. The app sets the controller factory up to use this global container. I would like to refactor this such that each one of my portable areas leverages it's own child Unity container, so that different areas can implement interfaces in varying ways. It seems like I would need to have a different ControllerFactory per area. How would I accomplish that, given that the following sets the factory for all?

How do I fetch the PHP DI container?

十年热恋 提交于 2019-12-13 10:30:05
问题 How do I load a database container using PHP DI? This is one of the variations I have tried up until now. Settings.php <?php use MyApp\Core\Database; use MyApp\Models\SystemUser; return [ 'Database' => new Database(), 'SystemUser' => new SystemUser() ]; init.php $containerBuilder = new \DI\ContainerBuilder(); $containerBuilder->addDefinitions('Settings.php'); $container = $containerBuilder->build(); SystemUserDetails.php <?php namespace MyApp\Models\SystemUser; use MyApp\Core\Database; use