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

  • SEARCH
  • Home
  • 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 8330521
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T02:08:52+00:00 2026-06-09T02:08:52+00:00

I am trying to get a basic service layer working in my application, but

  • 0

I am trying to get a basic service layer working in my application, but I’m running into trouble.

Interface:

public interface IEmailer
    {
        string ServiceTest();
    }

Service:

public class SimpleMailer : IEmailer
    {
    public string ServiceTest()
        {
            var ServiceVar = "This is your service working";
            return ServiceVar;
        }
    }

Controller:

    public class EmailSendController : Controller
    {

    private IEmailer _service;

     public EmailSendController()
        {
            _service = new SimpleMailer();

        }

        public EmailSendController(IEmailer service)
        {
            _service = service;
        }

        [HttpPost]
        public ActionResult Edit()
        {

            _service.ServiceTest();

            return View();
        }
    }
}

I am getting an error that _service.ServiceTest(); is null. What am I doing wrong that’s preventing it from returning ServiceVar?

  • 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-09T02:08:52+00:00Added an answer on June 9, 2026 at 2:08 am

    It all depends on what controller constructor is being hit. If you are hitting the constructor that takes an IEmailer parameter then you’ll need to have a way of creating the SimpleMailer concrete class to supply to the constructor. A typical way of having this controller created with that instance is to use dependency injection. I’m assuming it’s attempting to create the controller with that constructor because of the null reference exception that happened.

    Could you please post your mapping code for Ninject along with your Global.asax.cs code so we can see exactly how your implementing your Ninject container? It’s hard to pin point what the issue could be without seeing the code.

    Not only do you have to set up a container in the Application_start but you’ll also need an IDependencyResolver implementation for Ninject which should be available via NuGet if you look. That’s how your controller’s will be able to look up their parameter’s concrete implementations in order to create the controller.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to get a basic sample across domains working, but I just cannot
I'm trying to get a basic flip animation transition working when I push a
I've been trying to get a basic OAuth interaction working without success. There are
I'm trying to get a basic Spring Integration configuration running with JMS. The problem
I have a service defined as follows. public String getData(@QueryParam(date) Date date) I'm trying
I'm trying to send a very basic XML string from a Windows Phone application
I'm trying to get a basic Apache 2.2 load balancer running on top of
I'm trying to get a simple Spring.NET webservice working with MVC3 but although there
What I am doing is trying to get a basic GPS working and can't
I am trying to get basic functionality working to test with the Android C2DM

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.