dependency-injection

Configuring Ninject to return a list of results

眉间皱痕 提交于 2019-12-23 02:01:28
问题 I'm using Ninject to resolve dependencies and it's working swimmingly until now. In this example, I actually need a list of objects initialized based on data stored in my App.config. However, Ninject keeps returning an empty list. The snippet below is an example of what I tried. I've included the constructors for the class hierarchy for some context. public ServiceSchedulerBuilder(IList<ITextExportService> textExportServices) { _textExportService = textExportServices; } public

Spring. Dynamic dependency injection

烂漫一生 提交于 2019-12-23 00:52:42
问题 I have the following problem. I have a generic class A public class A<T, DAO extends JpaRepository<?, ?>> { @Autowired protected DAO daoObject; ...... and there I am trying inject a genreic DAO-object of the JpaRepository-type. If I have only one implemetation of injected object(of JpaRepository), then there is no problem, but if I have more then one, then spring doesn't know which object it is to inject and throws an exception. The question is: How can I dynamish based on generic information

Lua: can I use “require” as a form of dependency injection?

此生再无相见时 提交于 2019-12-22 20:27:12
问题 I'm designing a hospital integration system which consumes data from various hospitals (our customers), and then applies specific business rules to said data based on reading configurations from a database. If I were using Java, my first instinct would be to build a series of interfaces representing the various business rules, and then inject concrete instances (using Spring/guice) to compose a fully configured object. This would allow me to achieve a clean separation between configuration

Python: equivalent of input using sys.stdin

青春壹個敷衍的年華 提交于 2019-12-22 19:24:54
问题 I want to test some (python 3) code that directly uses the print and input functions. As I understand it, the easiest way to do this is by dependency injection: modifying the code so that it takes input and output streams as arguments, using sys.stdin and sys.stdout by default and passing in mock objects during testing. It's obvious what to do with print calls: print(text) #replaced with... print(text, file=output_stream) However, input doesn't have arguments for input and output streams.

Python: equivalent of input using sys.stdin

瘦欲@ 提交于 2019-12-22 19:24:10
问题 I want to test some (python 3) code that directly uses the print and input functions. As I understand it, the easiest way to do this is by dependency injection: modifying the code so that it takes input and output streams as arguments, using sys.stdin and sys.stdout by default and passing in mock objects during testing. It's obvious what to do with print calls: print(text) #replaced with... print(text, file=output_stream) However, input doesn't have arguments for input and output streams.

Dependency Injection with Non-Classes

♀尐吖头ヾ 提交于 2019-12-22 18:35:15
问题 I am somewhat new to Dependency Injection. I have set it up for some classes that pass in their dependencies as parameters in the constructor, but I have some constructors that take primitives like String or boolean . Obviously these need to be removed from the constructor if I am to use Dependency Injection for that class. For a case like this, what is a "best" practice? Make the constructor just take the dependencies and provide a setter method for all of the primitives that the class

Dependency injection with EF DbContext that implements 2 interfaces

白昼怎懂夜的黑 提交于 2019-12-22 18:24:03
问题 Given a DbContext that implements 2 interfaces like so: public interface IQueryEntities { IQueryable<User> Users { get; } IQueryable<Computer> Computers { get; } // other IQueryable<T> get properties } public interface IUnitOfWork { int SaveChanges(); } public class MyContext : DbContext, IQueryEntities, IUnitOfWork { // implement interfaces using EF } First question, is it a bad idea to separate out the query aspects of DbContext (IDbSets) from the command aspects (SaveChanges)? I am

How to trigger Eloquent Manager in Slim 3.1 Dependency Injection

我的梦境 提交于 2019-12-22 14:54:08
问题 I have write my code to instantiate Eloquent Capsule/Manager using slim DI like this $container['db'] = function ($c) { $settings = $c->get('database'); $db = new \Illuminate\Database\Capsule\Manager; $db->addConnection($settings); $db->setAsGlobal(); $db->bootEloquent(); return $db; } And I have my route like this $app->get('/adduser', function() { $user = new Users; $user->name = "Users 1"; $user->email = "user1@test.com"; $user->password = "My Passwd"; $user->save(); echo "Hello, $user-

configuration settings and IoC

假装没事ソ 提交于 2019-12-22 14:49:06
问题 I use IoC (DI) approach and usually have parameters, which are being read from configuration settings (i.e. connection strings, static values etc) by the lowest layer (DB layer etc). What is the best way to do it? Read directly in this the lowest layer, i.e.: string sendGridApiKey = ConfigurationManager.AppSettings["SendGridApiKey"]; It works, but need to add also this key to config file of unit test project. Also, assembly depends on configuration file Read it in the highest layer (i.e. web

configuration settings and IoC

蹲街弑〆低调 提交于 2019-12-22 14:49:01
问题 I use IoC (DI) approach and usually have parameters, which are being read from configuration settings (i.e. connection strings, static values etc) by the lowest layer (DB layer etc). What is the best way to do it? Read directly in this the lowest layer, i.e.: string sendGridApiKey = ConfigurationManager.AppSettings["SendGridApiKey"]; It works, but need to add also this key to config file of unit test project. Also, assembly depends on configuration file Read it in the highest layer (i.e. web