I have some problem with InSingletonScope().
My interface:
public interface ISettingsManager
{
ApplicationSettings Application { get; }
}
and my class:
public class SettingsManager : ISettingsManager
{
private readonly IConfigurationService _configurationService;
private readonly Lazy<ApplicationSettings> _applicationSettings;
public ApplicationSettings Application { get { return _applicationSettings.Value; } }
private SettingsManager(IConfigurationService context)
{
_configurationService = context;
_applicationSettings = new Lazy<ApplicationSettings>(() => new ApplicationSettings(context));
}
}
and standard binding in NinjectWebCommon looks like this:
kernel.Bind<ISettingsManager>().To<SettingsManager>().InSingletonScope();
kernel.Bind<IConfigurationService >().To<ConfigurationService>().InRequestScope();
And when I use constructor injection or property injection in HomeController:
[Inject]
public ISettingsManager SettingsManager { private get;}
Then I get an error:
An error occurred when trying to create a controller of type 'Web.Controllers.HomeController'. Make sure that the controller has a parameterless public constructor.
Where is the problem? What is wrong with my Singleton?
I use in my project dependency injection and when I inject one interface in constructor, everything work fine. When I add ISettingsManagers I have many problems.
GlobalConfiguration.DependencyResolver
, 2) Why do you have property injection AND constructor injection on the same controller - or are you passing in some random arguments to your constructor. – Callum LiningtonGlobalConfiguration.DependencyResolver
? I use only standard NinjectWebCommon. 2) In my Home Controller I have some service injection (InRequestScope) and this is working fine. When I add ISettingsManager in second parameter in Home Controller (or in the property injection) I always get the error with parameterless public constructor – user3146344NinjectWebCommon
unless it looks like this link. Are you in WebApi or MVC or both? – Callum Linington