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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T11:14:04+00:00 2026-06-04T11:14:04+00:00

I have moderate experience in developing web applications using spring.net 4.0 , nhibernate 3.0

  • 0

I have moderate experience in developing web applications using spring.net 4.0 , nhibernate 3.0 for ASP.net based web applications. Recently I ran into a situation where I needed to use spring.net to inject my service dependencies which belong to the WorkerRole class. I created the app.config file as I normally did with the web.config files on for spring. Here it is for clarity. (I have excluded the root nodes)

<configSections>
    <sectionGroup name="spring">
      <section name="context" type="Spring.Context.Support.WebContextHandler, Spring.Web" requirePermission="false" />
      <section name="objects" type="Spring.Context.Support.DefaultSectionHandler, Spring.Core" requirePermission="false" />
      <section name="parsers" type="Spring.Context.Support.NamespaceParsersSectionHandler, Spring.Core" />
    </sectionGroup>
  </configSections>
    <spring>
    <context>
      <!-- Application services and data access that has been previously developed and tested-->
      <resource uri="assembly://DataAccess/data-access-config.xml" />
      <resource uri="assembly://Services/service-config.xml" />
      <resource uri="AOP.xml" />
      <resource uri="DI.xml"/>
    </context>
    <parsers>
      <parser type="Spring.Data.Config.DatabaseNamespaceParser, Spring.Data" />
      <parser type="Spring.Transaction.Config.TxNamespaceParser, Spring.Data" />
      <parser type="Spring.Aop.Config.AopNamespaceParser, Spring.Aop" />
    </parsers>
  </spring>

Similarly Here’s the AOP.xml

<object id="FilterServiceProxy" type="Spring.Aop.Framework.ProxyFactoryObject, Spring.Aop">
    <property name="proxyInterfaces" value="Domain.IFilterService"/>
    <property name="target" ref="FilterService"/>
    <property name="interceptorNames">
      <list>
        <value>UnhandledExceptionThrowsAdvice</value>
        <value>PerformanceLoggingAroundAdvice</value>
      </list>
    </property>
  </object>
</objects>

and the DI.xml

<object type="FilterMt.WorkerRole, FilterMt" >
  <property name="FilterMtService1" ref="FilterServiceProxy"/>
</object>

However, I was unable to inject any dependencies into the worker role. Can someone please let me know what I am doing wrong here ? Is there a different way to configure Spring.net DI for windows azure applications ?

I don’t get any configuration errors but I see that the dependencies have not been injected because the property object to which I’ve tried injection, remains null.

  • 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-04T11:14:05+00:00Added an answer on June 4, 2026 at 11:14 am

    Based on my experience, you cannot inject anything into your WorkerRole class (the class that implements RoleEntryPoint). What I do, so far with Unity (I also built my own helper for Unity to help me inject Azure settings), is that I have my own infrastructure that runs and is built by Unity, but I create it in the code for the worker role.

    For example, I initialize the dependency container in my OnStart() method of RoleEntry point, where I resolve anything I need. Then in my Run() method I call a method on my resolved dependency.

    Here is a quick, stripped off version of my RoleEntryPoint’s implementation:

    public class WorkerRole : RoleEntryPoint
    {
        private UnityServiceHost _serviceHost;
        private UnityContainer _container;
    
        public override void Run()
        {
            // This is a sample worker implementation. Replace with your logic.
            Trace.WriteLine("FIB.Worker entry point called", "Information");
            using (this._container = new UnityContainer())
            {
                this._container.LoadConfiguration();
                IWorker someWorker = this._container.Resolve<IWorker>();
                someWorker.Start();
    
                IWorker otherWorker = this._container.Resolve<IWorker>("otherWorker");
                otherWorker.Start();
    
                while (true)
                {
                    // sleep 30 minutes. we don't really need to do anything here.
                    Thread.Sleep(1800000);
                    Trace.WriteLine("Working", "Information");
                }
            }
        }
    
        public override bool OnStart()
        {
            // Set the maximum number of concurrent connections 
            ServicePointManager.DefaultConnectionLimit = 12;
    
            // For information on handling configuration changes
            // see the MSDN topic at http://go.microsoft.com/fwlink/?LinkId=166357.
    
            this.CreateServiceHost();
    
            return base.OnStart();
        }
    
        public override void OnStop()
        {
            this._serviceHost.Close(TimeSpan.FromSeconds(30));    
            base.OnStop();
        }
    
        private void CreateServiceHost()
        {
            this._serviceHost = new UnityServiceHost(typeof(MyService));
    
            var binding = new NetTcpBinding(SecurityMode.None);
            RoleInstanceEndpoint externalEndPoint =
                RoleEnvironment.CurrentRoleInstance.InstanceEndpoints["ServiceEndpoint"];
            string endpoint = String.Format(
                "net.tcp://{0}/MyService", externalEndPoint.IPEndpoint);
            this._serviceHost.AddServiceEndpoint(typeof(IMyService), binding, endpoint);
            this._serviceHost.Open();
        }
    

    As you can see, my own logic is IWorker interface and I can have as many implementations as I want, and I instiate them in my Run() method. What I do more is to have a WCF Service, again entirely configured via DI with Unity. Here is my IWorker interface:

    public interface IWorker : IDisposable
    {
        void Start();
        void Stop();
        void DoWork();
    }
    

    And that’s it. I don’t have any “hard” dependencies in my WorkerRole, just the Unity Container. And I have very complex DIs in my two workers, everything works pretty well.

    The reason why you can’t interfere directly with your WorkerRole.cs class, is that it is being instantiated by the Windows Azure infrastructure, and not by your own infrastructure. You have to accept that, and built your infrastructure within the WorkerRole appropriate methods. And do not forget that you must never quit/break/return/exit the Run() method. Doing so will flag Windows Azure infrastructure that there is something wrong with your code and will trigger role recycling.

    Hope this helps.

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

Sidebar

Related Questions

I am a C/C++ programmer with moderate experience in desktop application. (no web development).
AU-contains numbers from 0-20 AV-needs to have high, moderate, low; based on the number
I have to port a smaller windows forms application (product configurator) to an asp.net
I'm a moderate to good PHP programer and have experience with terminal/shell scripts but
We have a moderate size (40-odd function) C API that needs to be called
Have a look at this picture alt text http://www.abbeylegal.com/downloads/2009-04-01/web%20part%20top%20line.jpg Does anyone know what css
I have a moderate-sized file (4GB CSV) on a computer that doesn't have sufficient
I have a handful of servers all connected over WAN links (moderate bandwidth, higher
I have a code library written in plain old C++ (no .NET/managed code) and
I have been developing a plugin for Eclipse. The plugin has a couple of

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.