constructor-injection

Is constructor injection possible in Spring configuration classes?

◇◆丶佛笑我妖孽 提交于 2019-12-02 04:33:51
问题 If I have a Spring configuration class (i.e. a class annotated with @Configuration) can I use constructor injection ? As it stands if I add one I get a no default constructor message, and if I add a default constructor it uses that rather than the overloaded one, which doesn't really help. 回答1: There is a bug report about this limitation. It will be fixed with Spring 4.3. Please note that another bug report ( not fixed yet today fixed in 4.3-RC1) report a problem when using this very new

Failure to pass generic arguments with Castle Windsor

一曲冷凌霜 提交于 2019-12-02 04:14:21
There seems to be an issue with passing generic arguments when attempting to create a parametrized instance with Castle Windsor Demo of Failure to Pass Generic Arguments private static void Main(string[] args) { PassGenericParamAtResolutionTime(); Console.ReadLine(); } private static void PassGenericParamAtResolutionTime() { Console.WriteLine("Passing generic argument fails"); var container = new WindsorContainer(); container.Register(Component.For<ISandCoordinator<Simpleton>>() .ImplementedBy<SandCoordinator<Simpleton>>()); var runtimeConstructorParam = new GenericManager<Simpleton>( "This Id

Is constructor injection possible in Spring configuration classes?

大城市里の小女人 提交于 2019-12-02 01:08:15
If I have a Spring configuration class (i.e. a class annotated with @Configuration) can I use constructor injection ? As it stands if I add one I get a no default constructor message, and if I add a default constructor it uses that rather than the overloaded one, which doesn't really help. There is a bug report about this limitation. It will be fixed with Spring 4.3. Please note that another bug report ( not fixed yet today fixed in 4.3-RC1) report a problem when using this very new feature and injecting generics in constructor of a @Configuration class. In Spring 4.3, you can use org

StructureMap: Choose concrete type of nested dependency

╄→гoц情女王★ 提交于 2019-12-01 17:57:46
Calculators: public interface ICalculator { int Calculate(int a, int b); } public class Calculator : ICalculator { private readonly ICalculatorStrategy _calculatorStrategy; public Calculator(ICalculatorStrategy calculatorStrategy) { _calculatorStrategy = calculatorStrategy; } public int Calculate(int a, int b) { return _calculatorStrategy.Calculate(a, b); } } Calculator stragies: public interface ICalculatorStrategy { int Calculate(int a, int b); } public class AdditionCalculator : ICalculatorStrategy { public int Calculate(int a, int b) { return a + b; } } public class MultiplyCalculator :

GlassFish, CDI and constructor injection

微笑、不失礼 提交于 2019-12-01 06:28:19
Is constructor injection supported in GlassFish 3.1's implementation of CDI for managed beans? I have a @Singleton EJB into which I want to inject another managed bean (contained in the same EJB module) using constructor injection. Field injection does work. But with constructor injection I get a NullPointerException from AbstractSingletonContainer . This does work: @Singleton public class FooBean implements Foo { @Inject private BarBean bar; } This does not work: @Singleton public class FooBean implements Foo { private final BarBean bar; @Inject public FooBean(BarBean bar) { this.bar = bar; }

EasyMock: Mock out a constructor call in java

情到浓时终转凉″ 提交于 2019-12-01 03:54:39
I have a looked at similar questions on this board, but none of them answer my question. This sound strange, but is it possible to mock out a constructor call on the object you're mocking. Example: class RealGuy { .... public void someMethod(Customer customer) { Customer customer = new Customer(145); } } class MyUnitTest() { public Customer customerMock = createMock(Customer.class) public void test1() { //i can inject the mock object, but it's still calling the constuctor realGuyobj.someMethod(customerMock); //the constructor call for constructor makes database connections, and such. } } How

GlassFish, CDI and constructor injection

筅森魡賤 提交于 2019-12-01 03:48:48
问题 Is constructor injection supported in GlassFish 3.1's implementation of CDI for managed beans? I have a @Singleton EJB into which I want to inject another managed bean (contained in the same EJB module) using constructor injection. Field injection does work. But with constructor injection I get a NullPointerException from AbstractSingletonContainer . This does work: @Singleton public class FooBean implements Foo { @Inject private BarBean bar; } This does not work: @Singleton public class

EasyMock: Mock out a constructor call in java

痴心易碎 提交于 2019-12-01 00:36:33
问题 I have a looked at similar questions on this board, but none of them answer my question. This sound strange, but is it possible to mock out a constructor call on the object you're mocking. Example: class RealGuy { .... public void someMethod(Customer customer) { Customer customer = new Customer(145); } } class MyUnitTest() { public Customer customerMock = createMock(Customer.class) public void test1() { //i can inject the mock object, but it's still calling the constuctor realGuyobj

Design By Contract, writing test-friendly code, object construction and Dependency Injection putting all together best practices

梦想的初衷 提交于 2019-11-30 10:20:19
I have been trying to figure out the best practices to write test-friendly code, but more specifically the practices related to object construction. In the blue book we discovered that we should enforce invariants when creating objects to avoid the corruption of our entities, value objects, etc. with this thought in mind, Design By Contract seems like the solution to avoid the corruption of our objects, but when we follow this, we could end up writing code like this: class Car { //Constructor public Car(Door door, Engine engine, Wheel wheel) { Contract.Requires(door).IsNotNull("Door is

Multi-tenancy web application with filtered dbContext

 ̄綄美尐妖づ 提交于 2019-11-30 05:41:50
I am new to ASP.Net MVC and multi-tenancy web application. I have done lots of reading, but being a beginner I just follow what I understand. So I managed to built a sample scenario web application and need to solve the ending part of it. Hope this scenario will be useful for some other beginners as well, but would welcome any other approach. Thanks in advance 1) Database in SQLServer 2008. 2) Data layer: C# class library project called MyApplication.Data public class AppUser { [Key] public virtual int AppUserID { get; set; } [Required] public virtual int TenantID { get; set; } [Required]