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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T16:17:22+00:00 2026-05-12T16:17:22+00:00

I have a created a simple Custom ServiceHost that inherits from ServiceHost and overrides

  • 0

I have a created a simple Custom ServiceHost that inherits from ServiceHost and overrides the method InitializeRuntime.

How do i change my app.config / web.config to use the custom service host so my overriden InitializeRunTime is executes..

I see attributes in the config file like behaviorConfiguration etc but nothing obvious where i can force it to use my Custom ServiceHost

My ServiceHost is simple :-

public class UnityServiceHost : ServiceHost
{
    protected override void InitializeRuntime()
    {

        //DO MY UNITY INJECTION HERE 
        //Console.WriteLine("");
        base.InitializeRuntime();
    }


}

Any help really appreciated.

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-05-12T16:17:23+00:00Added an answer on May 12, 2026 at 4:17 pm

    Oran Dennison describes how to do this using Spring.NET: http://orand.blogspot.com/2006/10/wcf-service-dependency-injection.html

    In summary, you’ll use WCF’s “behavior injection” to supply an instance of the service created by your DI container.

    1) Create custom IInstanceProvider implementation with the GetInstance method returning the service object created by your container:

        public object GetInstance(InstanceContext instanceContext, Message message)
        {
            return _container.Resolve(_serviceType);
        }
    

    2) Implement a custom IServiceBehaviour that adds your custom IInstanceProvider to each endpoint configuration.

        public void ApplyDispatchBehavior(ServiceDescription serviceDescription, ServiceHostBase serviceHostBase)
        {
            foreach (ChannelDispatcherBase cdb in serviceHostBase.ChannelDispatchers)
            {
                ChannelDispatcher cd = cdb as ChannelDispatcher;
                if (cd != null)
                {
                    foreach (EndpointDispatcher ed in cd.Endpoints)
                    {
                        ed.DispatchRuntime.InstanceProvider = 
                            new YourCustomInstanceProvider(serviceDescription.ServiceType);
                    }
                }
            }
        }
    

    3) In your custom service host, override OnOpening and add your custom service behavior

        protected override void OnOpening()
        {
            this.Description.Behaviors.Add(new CustomServiceBehavior());
            base.OnOpening();
        }
    

    Note that you may have to pass down your UnityContainer instance through to the IInstanceProvider so that it can do the resolving.

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

Sidebar

Related Questions

I created a simple custom control that only inherits from the Literal control, and
I have a custom control Workspace that inherits from Control and within it is
i have created a simple custom module to store title, date and content from
Could someone help me on this, I have created simple web services using axis2
I have created a simple WordPress plugin that automatically sets my new sites up
I have created a simple web browser using c# and I want to block
I have created a simple windows service that periodically checks a remote database via
I have created a custom validation rule (uniqueUserName). The problem I'm having is that
I have just created a mid-sized web-application using Java, a custom MVC framework, javascript.
I have the following simple custom control that I have defined for a Windows

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.