dependency-injection

Simple Injector fails to inject per Web API request registered class during Owin startup

て烟熏妆下的殇ゞ 提交于 2019-12-12 07:48:48
问题 I'm creating an API using Owin, Web API, Entity Framework, ASP.NET Identity. I'm using Simple Injector as my DI framework of choice. During the Owin startup process, I want to seed my database with some sample data. This is handled by a class implementing IDatabaseInitializer , which looks something like this: public class MyDbInitializer : DropCreateDatabaseAlways<MyDataContext> { private readonly IUserManager _userManager; public MyDbInitializer(IUserManager userManager) { _userManager =

Inject Services in Grails Unit Test

烂漫一生 提交于 2019-12-12 07:48:02
问题 I know that you can simply inject a service in unit test method using: defineBeans { someService(SomeService) } But when I need to inject service inside a service (the service someService calls itself another service some2Service ). When I run the test with above code I receive: Message: Cannot invoke method someMethod() on null object Is it possible to inject a service into a service in the unit test? Thanks. ;-) 回答1: To use spring beans in a unit test you need to do the following: Include

Dependency Injection for Procedural Programming

泄露秘密 提交于 2019-12-12 07:47:22
问题 Suppose I've decided to write a large application in C, or any other procedural programming language. It has functions with call-dependencies that look like this: A | +-------------+ | | B1 B2 | | +------+ +------+ | | | | C11 C12 C21 C22 Obviously, unit-testing the leaves functions, C11, C12, C21, and C22 is very easy: Setup the inputs, invoke the functions, assert the outputs. But what is the proper strategy to enable good unit-testing for B1, B2 and A? Would Dependency Injection suggest

Android functional testing with Dagger

℡╲_俬逩灬. 提交于 2019-12-12 07:46:30
问题 I’m trying to test an Activity with Mockito & Dagger. I have been able to inject dependencies to Activity in my application but when testing the Activity, I have not been able to inject mock to the Activity. Should I inject Activity to test or let getActivity() create it? public class MainActivityTest extends ActivityInstrumentationTestCase2<MainActivity> { @Inject Engine engineMock; private MainActivity mActivity; private Button mLogoutBtn; public MainActivityTest() { super(MainActivity

Ninject error in WebAPI 2.1 - Make sure that the controller has a parameterless public constructor

杀马特。学长 韩版系。学妹 提交于 2019-12-12 07:44:45
问题 I have the following packages and their dependencies installed in my WebAPI project: Ninject.Web.WebApi Ninject.Web.WebApi.OwinHost I am running this purely as a web-api project. No MVC. When I run my application and send a POST to the AccountController's Register action I get the following error returned: { "message":"An error has occurred.", "exceptionMessage":"An error occurred when trying to create a controller of type 'AccountController'. Make sure that the controller has a parameterless

What does AsSelf do in autofac? [duplicate]

谁说我不能喝 提交于 2019-12-12 07:41:16
问题 This question already has an answer here : What is self-binding in an IoC container? (1 answer) Closed 2 years ago . What is AsSelf() in autofac? I am new to autofac, what exactly is AsSelf and what are the difference between the two below? builder.RegisterType<SomeType>().AsSelf().As<IService>(); builder.RegisterType<SomeType>().As<IService>(); Thank you! 回答1: Typically you would want to inject interfaces, rather than implementations into your classes. But let's assume you have: interface

configurable dependencies with easy to mock out default implementations

一曲冷凌霜 提交于 2019-12-12 07:03:45
问题 I'm working on a kind of parameter values parser library. I'd like to have an Parser defined as follows: public class Parser { private ValuesConfiguration configuration; private ValuesProvider valuesProvider; private ValuesMapper valuesMapper; public Parser(ValuesConfiguration configuration) { this.configuration = configuration; } public Result parse(String parameterName) { List<Values> values = valuesProvider.getValues(parameterName); // do other stuff on values // ... return valuesMapper

angular factory dependency injection

这一生的挚爱 提交于 2019-12-12 06:58:49
问题 I'm trying to move some generic navigation formatting code from the controller into a factory. Do I need to inject $scope into my factory? I've tried six ways from Sunday to inject $scope, but every method I've tried gives me errors. Or do my stagesHeight, stagesWidth variables in the factory need scoping at all? controller: angular.module('sysomos.ads'). controller('LinkController', ['$scope', '$state', '$api', 'LinkFactory', function($scope, $state, $api, LinkFactory) { console.log

Passing data from one VM to another VM, using Unity and prism EventAggregator

*爱你&永不变心* 提交于 2019-12-12 06:33:19
问题 Trying to pass data from one ViewModel to another using prism EventAggregator, but when I debug on the subscriber, the data is null. Using version 5.0 of prism. Update Okay, I have tried implement the EventAggregator using prism 5.0 version. It still dosen't work, but here is what I have done. 1: Create event class public class RoomsSelectedEvent : PubSubEvent<ObservableCollection<Room>> { } 2: Inject IEventAggregator on publisher ViewModel (BookingViewModel) public class BookingViewModel :

Ninject and packaging service, infrastructure and data layers

亡梦爱人 提交于 2019-12-12 06:30:54
问题 I am a HUGE fan of ninject. To date however I have only used it for single application injections. I currently want to package up my services infrastructure and data layers that I have created. Basically my infrastructure layer has the contracts for creating the stored procedure Dao's that my services layer needs to pass to the data layer. The data layer does the SP call with the parameters added to the DAO and returns a dataset. All of this works excellently. I use constructor based