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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T11:20:43+00:00 2026-05-29T11:20:43+00:00

I have just changed from Ninject to TinyIoC for dependency injection and I’m having

  • 0

I have just changed from Ninject to TinyIoC for dependency injection and I’m having trouble with constructor injection.

I have managed to simplify it down to this snippet:

public interface IBar { } 

public class Foo
{
    public Foo(IBar bar) { }
}

public class Bar : IBar
{
    public Bar(string value) { }
}

class Program
{
    static void Main(string[] args)
    {
        var container = TinyIoCContainer.Current;

        string value = "test";
        container.Register<IBar, Bar>().UsingConstructor(() => new Bar(value));

        var foo = container.Resolve<Foo>();
        Console.WriteLine(foo.GetType());
    }
}

which causes a TinyIoCResolutionException to be thrown with:

"Unable to resolve type: TinyIoCTestApp.Foo"

and inside that exception is a chain of inner exceptions:

"Unable to resolve type: TinyIoCTestApp.Bar"
"Unable to resolve type: System.String"
"Unable to resolve type: System.Char[]"
"Value cannot be null.\r\nParameter name: key"

Is there something wrong with the way I’m using the constructor injection? I realize I could call

container.Register<IBar, Bar>(new Bar(value));

and that does indeed work, however the result is a global instance of Bar which is not what I’m after.

Any ideas?

  • 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-05-29T11:20:45+00:00Added an answer on May 29, 2026 at 11:20 am

    I’m not familiar with TinyIOC, but I think I can answer your question.

    The UsingConstructor registers a lambda that points at a constructor (the ctor(string)) that TinyIOC will use to do automatic constructor injection into. TinyIOC will analyse the constructor arguments, finds an argument of type System.String and tries to resolve that type. Since you haven’t registered System.String explicitly (which you shouldn’t btw), resolving IBar (and thus Foo) fails.

    The incorrect assumption you made is that TinyIOC will execute your () => new Bar(value)) lambda, which it will not. If you look at the UsingConstructor method you will propable see that it takes an Expression<Func<T>> instead of a Func<T>.

    The thing you want, is to register a factory delegate that does the creation. I expect TinyIOC to contain a method for this. It might look something like this:

    container.Register<IBar>(() => new Bar(value));
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have just changed my WPF application from .Net3.5 to .Net4. Doing this caused
I have just changed a compiler option from 4.0 to 4.2. Now I get
I just changed from Access to mySQL. I have a few tables, called Veranstaltung
I have just changed a column (called time) from t.string to t.datetime and then
I have just changed my page structure from eg /my_page.php to /my_page/ but now
Hi I am using Mysql 5.0.x I have just changed a lot of the
I have just installed a new ssl certificate on GlassFish 3. I also changed
just changed from Netbeans to Eclipse just for fun (Only developer on the company,
I have a form on an ASP.NET MVC site which I've recently changed from
We have just 'migrated' an SQL Server 2005 database from DEVEL into TEST. Somehow

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.