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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T05:20:46+00:00 2026-05-26T05:20:46+00:00

I am trying to bind a Func to an implementation of IService (Service1). Service1

  • 0

I am trying to bind a Func to an implementation of IService (Service1). Service1 takes the supplied IFormatter as a parameter. The type that is requesting the Service1 will be supplying the formatter instance (which is why im using a Func instead of just plain old IService. This is what I have done so far:

Bind<Func<IFormatter, IService>>()
    .ToMethod(context => formatter => 
        context.Kernel.Get<Service1>(new Parameter("formatter", formatter, false)));

Bind<Service1>().ToSelf().InSingletonScope();

This throws: “Injection of dependency IFormatter into parameter formatter of constructor of type Service1”.

how can i achieve a singleton of Service1 and allow the calling type to supply the IFormatter dependancy? i could get this working by simply:

Bind<Func<IFormatter, IService>>()
    .ToMethod(context => formatter => new Service1(formatter))
    .InSingletonScope();

however the returned Service1 instance is not a singleton. is this possible?

  • 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-26T05:20:46+00:00Added an answer on May 26, 2026 at 5:20 am

    You have to use ConstructorArgument instead of Parameter.

    Furthermore, I’d rethink your design. I think something is wrong with it. If you call the Func twice with different formatter instances you will not get what you would expect the second time if the service is a singleton. Most likely it is better to use a conditional binding for IFormatter than passing it to the service using a constructor argument.

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

Sidebar

Related Questions

I'm trying to bind a XAML ComboBox so that its list items are the
I'm trying to bind column visibility to that of another element like this: <Window
I'm trying to bind a <ul> element to a property that is an observableArray
I have a ASP.net gridview that I am trying bind to. My DataSource has
I am trying to bind a userControl that I create in a class as
Trying to bind a String to a RichTextBox.Text property so that when the String
Im trying to bind a list with datetime objects to my repeater. if (e.Item.ItemType
I'm trying to bind a list of data to a data grid, but can't
I am trying to bind a model coming from the server over json to
Hi I'm trying to bind data to a kendochart, but no bars are appearing

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.