dependency-injection

MEF & separate Interface assembly leads to “Interface for every class”

末鹿安然 提交于 2019-12-30 18:27:40
问题 I'm getting my feet wet with DI/IoC and MEF in particular. I have a web application that has two types of parts (maybe more someday) defined by interfaces which need access to the whole environment. The application has a list with concrete implementations for each type, composed by MEF. The environment consists of: several repositories current application request render engine navigation engine plus some static utility classes How can I put the Interface definitions in a seperate assembly and

MEF & separate Interface assembly leads to “Interface for every class”

社会主义新天地 提交于 2019-12-30 18:26:13
问题 I'm getting my feet wet with DI/IoC and MEF in particular. I have a web application that has two types of parts (maybe more someday) defined by interfaces which need access to the whole environment. The application has a list with concrete implementations for each type, composed by MEF. The environment consists of: several repositories current application request render engine navigation engine plus some static utility classes How can I put the Interface definitions in a seperate assembly and

Unit Testing IServiceCollection Registration

时光毁灭记忆、已成空白 提交于 2019-12-30 17:25:48
问题 I'm trying to figure out the easiest way to test my Service Registrations method for my framework. I'm creating dynamic services my registration looks like so: var messageHubConfig = new DynamicHubServiceConfiguration<Message, MessageDTO>(); messageHubConfig.SetDynamicHubOptions<AstootContext>(async (context, dto) => { return await context.ConversationSubscriptions .Where(x => x.ConversationId == dto.ConversationId && x.IsSubscribed) .Distinct() .Select(x => x.User.UniqueIdentifier)

Static methods: are they still bad considering PHP 5.3 late static binding?

£可爱£侵袭症+ 提交于 2019-12-30 17:23:21
问题 If you search on the reasons why static methods are bad the first thing you find it is because you can't override it when you are unit testing. So is this still true considering in PHP 5.3 you can do whatever you want with the introduction of static:: ? Add: http://sebastian-bergmann.de/archives/883-Stubbing-and-Mocking-Static-Methods.html Note he explains even how to use singleton without any testing problem: http://sebastian-bergmann.de/archives/882-Testing-Code-That-Uses-Singletons.html

Java WAR - Load Spring beans from an external JAR

强颜欢笑 提交于 2019-12-30 10:05:03
问题 I would like to load inside my Spring MVC Web Application (packaged as WAR) some Spring framework beans annotated with @Service from an external jar, which is in charge of accessing a database and located in the classpath under /WEB-INF/lib. If possible, it would be desirable to load them automatically using the @Autowired annotation. I have followed successfully the solution in this link1: this.ctx = new ClassPathXmlApplicationContext("services-context.xml"); this.myAService = ctx.getBean(

“No IUserTokenProvider is registered” when using structuremap dependency injection

拈花ヽ惹草 提交于 2019-12-30 09:47:29
问题 I have an MVC 5 project that has been modified to use int as the primary key for identity as shown in this guide I then enabled email confirmation as described in this guide Everything worked fine as expected. Then I installed structuremap.mvc5 for dependency injection and added modified DefaultRegistry.cs to public DefaultRegistry() { Scan( scan => { scan.TheCallingAssembly(); scan.WithDefaultConventions(); scan.AssemblyContainingType(typeof(MyProject.Data.MyDbContext)); scan.With(new

Override Autofac registration - Integration tests with DI

夙愿已清 提交于 2019-12-30 09:33:28
问题 I write integration tests for my application, and use my container for this. I want to be able to register all the components as I do in real running, and then override some of the components and switch them to use stubs implementations. I wouldn't want to seperate the DI and have a container for tests only because I want to test the real thing. Doing this also seems ugly: public class MyRegistrations { public static RegisterAll(bool isInTest= false) { if (isTest) { // Register test fakes }

NUnit integration tests and dependency injection

风格不统一 提交于 2019-12-30 09:00:08
问题 I'm currently making use of Castle Windsor version 2.1 as my container and would like to perform integration tests using the services registered with it. Currently, I do this my using the Common Service Locator to retrieve my service instance and perform my integration tests against it as such: var myService = ServiceLocator.Current.GetInstance<IMyService>(); // do stuff with myService What I'd ideally like to do is have my service dependencies injected into my NUnit test fixture

NUnit integration tests and dependency injection

*爱你&永不变心* 提交于 2019-12-30 09:00:03
问题 I'm currently making use of Castle Windsor version 2.1 as my container and would like to perform integration tests using the services registered with it. Currently, I do this my using the Common Service Locator to retrieve my service instance and perform my integration tests against it as such: var myService = ServiceLocator.Current.GetInstance<IMyService>(); // do stuff with myService What I'd ideally like to do is have my service dependencies injected into my NUnit test fixture

Why Mockito @InjectMocks might be a thing to avoid?

六月ゝ 毕业季﹏ 提交于 2019-12-30 08:38:31
问题 Why @InjectMocks might be a thing to avoid for this kind of test. @RunWith(MockitoJUnitRunner.class) public class MyClassTest { @Mock private Bar bar; @InjectMocks private Foo foo; // created by Mockito @Test public void shouldCallMethod() { // when foo.myMethod(); // then ... } } Foo.java public class Foo { private final Bar bar; public Foo(Bar bar) { this.bar = bar; } ... I read about this in comments to this answer: https://stackoverflow.com/a/21172873/516167 About @InjectMocks Mark a