Specify Ninject Property for Private

I have a project using Ninject. I am creating an interface and implementing it in another class. Add below code to register service

private static void RegisterServices(IKernel kernel)
{
    kernel.Bind<IArticleContent>().To<ArticleService>().InRequestScope();
}  

      

Create a web page and write the following code

[Inject]
public IArticleContent _ArticleContentService { get; set; }

      

Write some extra code to get the data bound to the control and everything works .

Then I change the specified public announcement to closed

[Inject]
private IArticleContent _ArticleContentService { get; set; }

      

And get

Exception Details: System.NullReferenceException: Object reference not set to object instance.

After some research, I added

new StandardKernel(new NinjectSettings() { InjectNonPublic = true });

      

to a class NinjectWebCommon

in the Start method (method is also used RegisterServices

), but the same error. So after further research, it seems to me that I need to do it in a different way (i.e. Inside the constructor of my service class), or I need the code above elsewhere.

Can anyone please advise on how to use a property with Ninject when it sets a private or "correct" way to do it?

+3
c # .net ninject repository-pattern


source to share


No one has answered this question yet

Check out similar questions:

1743
What's the best way to give a C # auto property an initial value?
6
Launching an application of registration mode dependent applications
3
Is it permissible in Ninject to inject IKernel into places?
2
Ninject providing a NullReferenceException
2
Engineering injection injection: reading bindings from config?
1
Ninject in MVC and WebAPI to create an abstract factory
1
How ninject does dependency injection in Asp.net MVC
1
Ninject: ninject.web - How to apply for a regular ASP.Net web page (! MVC)
0
Should I get rid of the entered variable after assignment
0
Ninject in N-Tier Application using WCF and InRequestScope



All Articles
Loading...
X
Show
Funny
Dev
Pics