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 9088355
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T21:53:33+00:00 2026-06-16T21:53:33+00:00

I have a small class that creates a new instance of a data processor

  • 0

I have a small class that creates a new instance of a data processor object each time it needs it. I am using injection for everything but I cannot figure out how to get an activated instance of IDataProcessingService without injecting the kernel.

Is there a better way to do this. I know I can make a static gateway rather than inject but I would think that is the same issue in a different skin.

public class DataProcessingManager
{
    private readonly Dictionary<IDataProcessingRequest, IDataProcessingService> _activeProcessingServices;

    private readonly IKernel _kernel;

    public DataProcessingManager(IKernel kernel)
    {
        _kernel = kernel;
        _activeProcessingServices = new Dictionary<IDataProcessingRequest, IDataProcessingService>(new DataProcessingRequestComparer());
    }

    public void ProcessFor(IDataProcessingRequest dataProcessingRequest)
    {
        if (!_activeProcessingServices.ContainsKey(dataProcessingRequest))
        {
            var _processingService = _kernel.Get<IDataProcessingService>();
            _activeProcessingServices.Add(dataProcessingRequest, _processingService);

            _processingService.ProcessingFinished += 
                (sender, args) => _activeProcessingServices.Remove(dataProcessingRequest);

            _processingService.Process(dataProcessingRequest);
        }
    }
}

EDIT 2 :

I had to change the accepted answer as the original suggested implementation was not creating new instances which is what I need. I know I could use the original answer by referencing the kernel but this is not what I want either. In the end the .ToFactory() convention in the new answer is the better way to do it.

I will contact the author of the extension and ask him to update the code sample as the Foo..Bar example is awkward to read.

  • 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-16T21:53:34+00:00Added an answer on June 16, 2026 at 9:53 pm

    If you want a new instance each time, you can use the Ninject Factory Extension to not depend on IKernel.

    Using this extension, you can create a factory interface to create instances of IDataProcessingService, but you do not need to implement that interface. This extension can implement it for you (which under the hood will call to IKernel).

    Factory interface…

    public interface IDataProcessingServiceFactory
    {
        IDataProcessingService Create();
    }
    

    Binding statement (which auto-generates the factory implementation at runtime)…

    kernel.Bind<IDataProcessingServiceFactory>().ToFactory();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this small class called City that simply holds some information about a
I have written a small webapp using the flask framework that involves plotting using
I have written a small program, while reading a book about swing, that creates
I have small class called 'Call' and I need to store these calls into
I have this small class looking like this: private static int field1 = -
I have a small class hierarchy where I would like to have a child
I have a small class with a timer, but don't have anything for the
I have a small utility class : public static class SerializationUtilities { public static
I have a small Java test app in Netbeans where the main() class reads
I have a small Python OOP program in which 2 class, Flan and Outil

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.