I have a Service created with ServiceStack. I am using Funq for my Dependency Injection as it comes with ServiceStack by default, but this may be behaviour exhibited by other DI containers.
I register my types on startup:
this.AppContainer.RegisterAs<ConcreteDownloadServices, IDownloadServices>();`
I have this constructor in a class:
private readonly IDownloadServices downloadServices;
public ExampleService(IDownloadServices downloadServices)
{
this.downloadServices = downloadServices;
}
And the constructor of my concrete implementation is:
public ConcreteDownloadServices()
{
this.ArbitraryProperty = "ArbitraryString";
}
Everything resolves fine and I can step into the code and see things working as expected. However, AbritraryProperty
does not get set properly. I can step through and see it set to the string value, but as soon as the code returns to the calling code (in this example, it would be the constructor of ExampleService
) ArbitraryProperty
is now null.
- Is this behaviour by design?
- If it is by design, does using DI mean that I shouldn't be doing anything in the constructors of my concrete implementations?
- If it is by design, what's the correct way to set default values for auto properties?
- If it is not by design, then what's going on?