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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T11:42:46+00:00 2026-06-09T11:42:46+00:00

Ok so I have looked at many posts on how to get DI working

  • 0

Ok so I have looked at many posts on how to get DI working with web API. Trying to do simple ctor injection. What I am pasting here works but that doesn’t mean I am happy with it. If anyone has some advice please sound off.

It appears we don’t have to take control over controller creation in WEB API, which makes me question the proper releasing of dependencies. I have things setup as scoped, you will see by looking at the code. We are forced to use IDependencyResolver which I think sucks but this is the only workaround I can find as no other hooks that I have tried with IControllerActivator seem to work.

SEE CODE.

public class WindsorWeApiResolver:WindsorWebApiDependencyScope,IDependencyResolver
{
    private readonly IWindsorContainer _container;

    public WindsorWeApiResolver(IWindsorContainer container) : base(container)
    {
        _container = container;
    }

    public IDependencyScope BeginScope()
    {
        return new WindsorWebApiDependencyScope(_container);
    }
}
public class WindsorWebApiDependencyScope:IDependencyScope
{
    private readonly IWindsorContainer _container;
    private readonly IDisposable _scope;

    public WindsorWebApiDependencyScope(IWindsorContainer container)
    {
        _container = container;
        _scope = _container.BeginScope();
    }

    public void Dispose()
    {
        _scope.Dispose();
    }

    public object GetService(Type serviceType)
    {
        return _container.Kernel.HasComponent(serviceType) ? _container.Resolve(serviceType) : null;

    }

    public IEnumerable<object> GetServices(Type serviceType)
    {
        return _container.ResolveAll(serviceType).Cast<object>().ToArray();
    }


}
  • 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-09T11:42:48+00:00Added an answer on June 9, 2026 at 11:42 am

    I agree that IDependencyResolver is not ideal. I tried to negate the lack of release method, without fighting MVC, by using the Typed Factory Facility for the scope. See my post here. Your controllers can take constructor args as usual.

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

Sidebar

Related Questions

I seem to have looked through many solution on here and the web and
have looked through many posts here on SO, and haven't found any that address
I've looked through some posts around here, but am still struggling to get my
(I've looked at many other similar posts on SO and have unfortunately not been
So, i have looked at many different ways and posts about saving and restoring
I have looked at many posts but unable to find an answer to my
I know there have been many posts regarding array sorting, but I have looked
Despite many posts I have looked through being of along the same lines as
I have looked at many other threads that show how to use accelerometer values,
I have looked at many different peoples answers to this problem but they only

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.