property-injection

Use Spring Data random (embedded) Mongo port with NoSQL JUnit @Rule

天涯浪子 提交于 2021-01-28 04:15:59
问题 I'm currently trying to write an Integration test class which uses Spring Data Mongo repositories. I use an embedded Mongo instance provided by the de.flapdoodle.embed.mongo dependency. Spring Data documentation specifies that we only have to put this dependency in the project and the EmbedMongoAutoConfiguration takes care of the rest. For now, that's ok, and setting the port to 0 makes the auto configuration process to find a free port to launch the mongo instance on. This feature is

Spring @Autowired and @Value on property not working

大兔子大兔子 提交于 2020-01-13 09:33:08
问题 I would like to use @Value on a property but I always get 0 (on int). But on a constructor parameter it works. Example: @Component public class FtpServer { @Value("${ftp.port}") private int port; public FtpServer(@Value("${ftp.port}") int port) { System.out.println(port); // 21, loaded from the application.properties. System.out.println(this.port); // 0??? } } The object is spring managed, else the constructor parameter wouldn't work. Does anyone know what causes this weird behavior? 回答1:

How to use Property Injection in MVC Core and AutoFac

北城余情 提交于 2019-12-23 10:51:40
问题 I can use Constructor Parameter Injection easily In MVC Core. But Property Injection is not supported.I try use AutoFac but fail too. So how to use Property Injection in MVC Core. Here is the code with AutoFac services.AddMvc(); ContainerBuilder builder = new ContainerBuilder(); builder.RegisterType<Test2>().As<ITest>(); builder.RegisterType<HomeController>().PropertiesAutowired(); builder.Populate(services); var container = builder.Build(); //The following code works HomeController test2 =

Windsor Container: How to specify a public property should not be filled by the container?

馋奶兔 提交于 2019-12-18 14:58:09
问题 When Instantiating a class, Windsor by default treats all public properties of the class as optional dependencies and tries to satisfy them. In my case, this creates a rather complicated circular dependency which causes my application to hang. How can I explicitly tell Castle Windsor that it should not be trying to satisfy a public property? I assume there must be an attribute to that extent. I can't find it however so please let me know the appropriate namespace/assembly. If there is any way

Ninject cyclic dependency - already using property injection

孤者浪人 提交于 2019-12-13 19:17:26
问题 I'm having a problem with a cyclic dependency in a project using dependency injection. In looking around, it seems that the only way to avoid it, other than restructuring (I did some of that too), is to use property injection. I tried this, and it doesn't seem to help, but I'm not sure why. Here is the path that's causing issues. Activation path: 6) Injection of dependency IUserRepository into property UserRepository of type ModelFactory{UserRole} 5) Injection of dependency IUserRoleFactory

Castle Windsor IoC property injection. Using property from BaseClass inside ChildClass constructor

妖精的绣舞 提交于 2019-12-13 04:39:40
问题 I have a base class as following public class BaseClass { public ISomeObject Property { get; set; } } and ChildClass inherited from BaseClass.I need to use Property from BaseClass inside ChildClass constructor, but it's not initialized by IoC as I want and has value null. And if I use it inside ChildClass's methods, Property is initialized. What am I doing wrong? Here is how I register ISomeObject in IoC container container.Register( Component.For<ISomeObject>() .ImplementedBy<WebSomeObject>(

Unity Static Property Injection

我们两清 提交于 2019-12-12 10:48:50
问题 I have two classes, one which sets up the container by registering types and one which contains a static property which I want to inject into. My issue is the property is never set by injection so when I call a method on it, the property is always null. public class ClassOne { public void Method() { Container.RegisterType<IClass, ClassImplOne>("ImplOne"); Container.RegisterType<IClass, ClassImplTwo>("ImplTwo"); } } public static class ClassTwo { [Dependency] public static IClass SomeProperty

UnityContainer.BuildUp() - Can I make it inject new instances into properties only if these are null?

戏子无情 提交于 2019-12-11 07:44:20
问题 I'm deserializing a class like this one class AClass{ [Dependency] AnotherClass Property{ get; set; } } When I then BuildUp() the object I'd like Unity to create a new instance of AnotherClass only if the property is null and otherwise just perform a BuildUp on it. Is there a simple way to achieve this? Edit: I'm doing mvvm with wpf. The classes are view-models, I serialize them as there are some properties I want to preserve between runs and they also have some dependencies I want unity to

How to prevent Castle Windsor from injecting property dependencies?

别来无恙 提交于 2019-12-11 02:13:31
问题 Is there a way to prevent Castle Windsor from automatically injecting dependencies into properties (besides the [DoNotWire] attribute)? 回答1: Duplicate: Windsor Container: How to specify a public property should not be filled by the container? See also: http://groups.google.com/group/castle-project-users/browse_thread/thread/f1ec737ff243c19d http://jfromaniello.blogspot.com/2009/07/noninjectable-service.html http://using.castleproject.org/display/Contrib/Castle.Facilities

Programatic property injection with Microsoft Unity

可紊 提交于 2019-12-10 18:22:23
问题 I use contructor injection in my solution, but this one class has a property that i do not want to pass in the constructor where i have the invariant dependencies. Let's say i got an ILogger and it has a FileName property i want to set, while still having it set the dependancies in the contructor. How do i go about registering the type, and at the same time pass the defaunt connection string. I hope there is an easy way to do it - preferably without decorating the property with an attribute,