Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9231383
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T06:03:13+00:00 2026-06-18T06:03:13+00:00

I have generic Result<T> generic class which I use often in methods to return

  • 0

I have generic Result<T> generic class which I use often in methods to return result like this

public Result<User> ValidateUser(string email, string password)

There is ILoggingService interface in Result class for logging service injection but I do not find a way to inject actual implementation.

I tried to execute the code below but TestLoggingService intance is not injected into LoggingService property. It always return null. Any ideas how to solve it?

 using (var kernel = new StandardKernel())
            {               
                kernel.Bind<ILoggingService>().To<TestLoggingService>();
                var resultClass = new ResultClass();
                var exception = new Exception("Test exception");
                var testResult = new Result<ResultClass>(exception, "Testing exception", true);                
            }  


      public class Result<T>
        {

           [Inject]
           public ILoggingService LoggingService{ private get; set; } //Always get null


            protected T result = default(T);
            //Code skipped




            private void WriteToLog(string messageToLog, object resultToLog, Exception exceptionToLog)
            {

                LoggingService.Log(....); //Exception here, reference is null



        }
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-18T06:03:14+00:00Added an answer on June 18, 2026 at 6:03 am

    You are creating the instance manually using new. Ninject will only inject objects created by kernel.Get(). Furthermore it seems you try to inject something into a DTO which is not recommended. Better do the the logging in the class that created the result:

    public class MyService
    {
        public MyService(ILoggingService loggingService) { ... }
    
        public Result<T> CalculateResult<T>() 
        {
            Result<T> result = ...
            _loggingService.Log( ... );
            return result;
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have generic type that looks like: public class GenericClass<T, U> where T :
I have outer generic class which has some inner class, for which I'd like
let's say i have this generic class which does some work and produces a
I have generic async task class which fetches response from server . And i
I have a generic class which represents a fragment of text. That fragment of
I have this code form the book SCJP: 1. class Mammal { 2. String
I am trying to use the generic DbSet class. I have tried adding the
I have a Software titles class which is defined as follows: public class SoftwareTitles
So I have a generic Matrix class that I created which has the following
I have this class... public class MyDTO { public int Id { get; set;

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.