Questions tagged [property-injection]
61 questions
15
votes
2 answers
Is it appropriate to use Property Injection in a base class when a dependency is only required in the base class?
Example:
public abstract class BaseControler : Controller
{
public IUnitOfWork UnitOfWork { get; set; }
}
public class HomeController : BaseControler
{
readonly IUserRepository _userRepository;
// :-)
public…

Rookian
- 19,841
- 28
- 110
- 180
14
votes
1 answer
How to inject dependency property using Ioc Unity
I have the following classes:
public interface IServiceA
{
string MethodA1();
}
public interface IServiceB
{
string MethodB1();
}
public class ServiceA : IServiceA
{
public IServiceB serviceB;
public string MethodA1()
{
…

Jin Ho
- 3,565
- 5
- 23
- 25
13
votes
7 answers
Windsor Container: How to specify a public property should not be filled by the container?
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. …

George Mauer
- 117,483
- 131
- 382
- 612
11
votes
3 answers
Spring @Autowired and @Value on property not working
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}")…

Jan Wytze
- 3,307
- 5
- 31
- 51
8
votes
5 answers
IoC with value type and object type dependencies
I am looking for suggestions as to the best way to design objects for IoC
Suppose I have an object (Service) that has a dependency to a DataContext which is registered with Ioc.
But it also requires a name property, i could design the object like…

Andre
- 3,717
- 4
- 25
- 29
8
votes
1 answer
How can I get Castle Windsor to automatically inject a property?
I have a property on my classes for logging service.
private ILogger logger = NullLogger.Instance;
public ILogger Logger
{
get { return logger; }
set { logger = value; }
}
And I have this in my component…

Chris Haines
- 6,445
- 5
- 49
- 62
7
votes
1 answer
Ninject 2 Property Injection for ActionFilterAttribute not working
I have a method attribute which expects several properties to be injected by Ninject 2, but userSession and jobRepository are coming up as null:
[AttributeUsage(AttributeTargets.Method, AllowMultiple = false)]
public class JobAttribute :…

DavGarcia
- 18,540
- 14
- 58
- 96
7
votes
2 answers
Unity Static Property Injection
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…

clicky
- 865
- 2
- 14
- 31
6
votes
2 answers
How to inject dependency name as a constructor parameter
Using Autofac, I can register a class to resolve against an interface using property injection, using the following code:
builder.RegisterType()
.As()
.PropertiesAutowired()
…

Digbyswift
- 10,310
- 4
- 38
- 66
5
votes
2 answers
How to handle circular references with Autofac 2.4.5?
The autofac wiki page about Circular References says to use:
cb.Register().OnActivated(ActivatedHandler.InjectUnsetProperties);
But it looks like ActivatedHandler does not exist anymore in 2.4.5. Digging around in the source, I found…

Ants
- 2,628
- 22
- 35
5
votes
2 answers
How to use Property Injection in MVC Core and AutoFac
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…

Siying Wang
- 71
- 2
- 4
4
votes
1 answer
Castle Windsor automatic property injection of non-public property
I've setup Castle Windsor in my ASP.NET Mvc 3 project and added the following property on HomeController:
private IUserService UserService
{
get;
set;
}
When I try using UserService in an action method it's always null.…

Lester
- 4,243
- 2
- 27
- 31
4
votes
0 answers
Prevent Autofac from aggressively injecting properties?
I have a simple class:
public class MyWidget
{
private string _something;
public MyWidget(string name)
{
}
public string Something
{
get { return _something; }
set { _something = value; }
}
}
that I…

Dan
- 1,215
- 1
- 10
- 22
4
votes
0 answers
Spring: Is it possible to inject external indexed property?
I have next application.properties file:
cassandra.connection.hosts[0]=host1.lab.org
cassandra.connection.hosts[1]=host2.lab.org
And I'm looking for a way to inject it as a list into a Spring bean - something like…

sedovav
- 1,986
- 1
- 17
- 28
3
votes
2 answers
Property / method injection using Autofac in filter attributes
Trying to use autofac for dependency injection by property.
The instance is always null and there is no dependency injected.
Below is class where the property needs to be injected.
public class UserAccount
{
public IAccountService AccountService…

MDT
- 1,535
- 3
- 16
- 29