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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T01:42:47+00:00 2026-06-17T01:42:47+00:00

i never use Dependency Injection in apps. i go through few article with Dependency

  • 0

i never use Dependency Injection in apps. i go through few article with Dependency Injection and found the concept is interesting but believe hard to implement in real life. now i want to implement Dependency Injection in my win form apps.

our company work with many shipping company like UPS, Fedex, Purolator etc for now but in future they have plan to works with many other shipping company. i have developed separate separate class library projects for all those shipping company like UPS, Fedex, Purolator and include those dll into our main form apps. the problem is many time we hard code few things in our code like country code etc.

for example i have one form where 4 buttons are there. like those buttons are “Ship with UPS WorldShip”, another button there called “Ship with UPS WebAPI”, another button there called “Ship with FedEX Desktop Apps” and another last button called “Ship with Fedex WebAPI”.

when user click on UPS WorldShip button then a flat file generate in a folder.
when user click on UPS WebAPI button then a request goes to UPS site.

when user click on FedEX WinApps button then a flat file generate in a folder.
when user click on FedEX WebAPI button then a request goes to FedEx site.

so what i do now when user click on any button then i call a specific function exist in dll to complete the task.

everything is working fine at my end but the problem is when our company start working with another new shipping company then i have to create another class library for that company.

i said i never use DI ever in my apps and have no experience. so some one guide me how could i handle my situation with DI as a result when a new shipping company will join then i do not have to write any extra code. so guide me how to implement DI in my apps and also guide me with how to handle my situation with sample DI code for guidance.

My second phase question

1) when i need to call InitializeKernel() function ? when application load or when form load

2) i am not familiar with ninject so i just do not understand what is the meaning of this line of code

.Configure((b, c) =>
b.InTransientScope().Named(c.Name)));

3) what c.Name would return?

4) i found no config file entry. ninject does not require config file entry like unity DI?

the code u gave looks very professional. if possible please answer all my points.

at last tell me is there any pdf available for ninject for learning DI and ninject code usage.

thanks

MY 3rd phase of question

very sorry and u r right InitializeKernel() declare once.

u said Ninject supports fluent configuration only then a problem could occur because when a new shipping company join then i have to change code with in this block like

using(var kernel = InitializeKernel())     
{
    // 4.1 resolve delivery services by names
    var upsWorldShip = kernel.Get<IShippingCompanyService>("ShippingUpsWorldShip");
    var fedExDesktopApps = kernel.Get<IShippingCompanyService>("ShippingFedExDesktopApps");


    var PurolatorExDesktopApps = kernel.Get<IShippingCompanyService>("PurolatorFedExDesktopApps");

    // 4.2 delivery processing
    upsWorldShip.Delivery();
    fedExDesktopApps.Delivery();

    // 5 PROFIT!
}

so here i need to add this line

var PurolatorExDesktopApps = kernel.Get<IShippingCompanyService>  ("PurolatorFedExDesktopApps");

the problem is whenever a new shipping related dll will be added then i have to add one line of code in the above block….that is not desirable.

if i could add all dll’s related info in config file and load & instantiated all classed from all dll from there it would be better. so i am looking for ur suggestion. thanks

  • 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-17T01:42:48+00:00Added an answer on June 17, 2026 at 1:42 am

    Seems that you’re asking for Configuration by Convention. This means that you identify groups of components that should share a common configuration and then specify that configuration in a single statement once read more about it

    In practice, this mean that you’ll deploy all libraries with selected functionality “delivery” into “special” location in your project, and inherit all implementation from “special” interface. Finally, make DI container to find them and configure all for you.

    Define Convention

    Here is a simple example how to achieve this using Ninject.Extensions.Conventions.

    Pay an attention to comments

    // 1 define "delivery" interface
    interface IShippingCompanyService
    {
        void Delivery();
    }
    
    // 2.1 — first assembly "Ups.Services.dll"
    public class ShippingUpsWorldShip : IShippingCompanyService
    {
        public void Delivery()
        {
            "Ship with UPS WorldShip".Dump();
        }
    }
    
    // 2.2 — first assembly "FedEx.Services.dll"
    public class ShippingFedExDesktopApps : IShippingCompanyService
    {
        public void Delivery()
        {
            "Ship with FedEX Desktop Apps".Dump();
        }
    }
    

    Define Configuration

    Build configuration using Ninject Kernel (StandardKernel in this case)

    // 3 kernel configuration
    public static IKernel InitializeKernel() 
    { 
        var kernel = new StandardKernel();
    
        kernel.Bind(x => x
             // 3.1 search in current assembly
            .FromThisAssembly()
                .SelectAllClasses() // 3.2 select all classes implement "special" interface
                .InheritedFrom<IShippingCompanyService>()
            // 3.3 search all assemblies by wildcards
            .Join.FromAssembliesMatching("./*Services.dll")
                .SelectAllClasses() // 3.2 select all classes implement special interface
                .InheritedFrom<IShippingCompanyService>()
            // 3.4 bind to "special" interface
            .BindAllInterfaces()
            // 3.5 configure lifetime management and dependency name
            .Configure((b, c) => 
                b.InTransientScope().Named(c.Name)));
    
        return kernel; 
    } 
    

    How to resolve dependencies

    From Composition root of application resolve delivery services by names

    // 4 from your Compositon Root ...
    using(var kernel = InitializeKernel())     
    {
        // 4.1 resolve delivery services by names
        var upsWorldShip = kernel.Get<IShippingCompanyService>("ShippingUpsWorldShip");
        var fedExDesktopApps = kernel.Get<IShippingCompanyService>("ShippingFedExDesktopApps");
    
        // 4.2 delivery processing
        upsWorldShip.Delivery();
        fedExDesktopApps.Delivery();
    
        // 5 PROFIT!
    }
    

    All sources available here

    Summary

    Configuration by Convention is very helpful approach already adopted in many projects. Nevertheless, I recomment you to read Mark Seemann book “Dependency Injection in .NET” and watch his talk about conventions.

    Answers

    1. when i need to call InitializeKernel() function ? when application load or when form load,
      • at app start, at Composition Root
    2. i am not familiar with ninject so i just do not understand what is the meaning of this line of code: .Configure((b, c) => b.InTransientScope().Named(c.Name)))
      • Every time dependency injected, new instance will be create
      • Dependencies could be refered by their class name
    3. what c.Name would return?
      • Class name
    4. i found no config file entry. ninject does not require config file entry like unity DI?
      • Ninject supports fluent configuration only
    5. u declare two method of having same name called InitializeKernel() the 2nd InitializeKernel() is for what?
      • There is only one declaration of method InitializeKernel()
    6. at last tell me is there any pdf available for ninject for learning DI and ninject code usage
      • The best place to learn about Ninject is from the official wiki
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've never used malloc to store more than values but I have to use
I've used mime_content_type() and File info but i never successed. i want to use
I consider myself an experienced programmer and understand the basic concept of dependency injection.
I'm a newbie to Dependency Injection. I have never used and never even undestood
Is it considered a bad practice to use optional parameters when using dependency injection
In my WPF application I use the MVVM pattern together with dependency injection. The
Im starting to use Axis2, never worked with it before. Maven was a dependency
I use only classes and never use IDs. Many people like to use IDs
I have noticed that most Objective-C coders never use the self->ivar syntax when accessing
I've never had the need to really ever use any of the .NET Data

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.