Can someone help me try to figure out what's going on here? I have a
windows service that occasionally crashes and restarts (which is a
different problem we need to address, but not the immediate problem). The
windows service recovery options is set to restart the service when this
happens.
The problem I am encountering is that once the service restarts, the call
to _dbProxy.GetQueuedJobs() is getting a null reference exception. I
believe the _dbProxy object is null upon a restart. So I am wondering if
the WindowsService OnStart method isn't getting invoked, and
therefore Windsor.Install(new WindsorInstaller()) isn't getting called?
Is there a way to check if the Container needs to be registered again? Or
some better method of ensuring the dependencies in ExtractionManagerService
have been passed in by Windsor (and if not perhaps new up WindsorFactory()
again)?
Any suggestions/ideas/help appreciated!
namespace ExtractionManager.Service
{
[SecurityPermission(SecurityAction.Demand, ControlAppDomain = true)]
partial class WindowsService : ServiceBase
{
public ServiceHost ServiceHost;
private static readonly ILog Log = LogManager.GetLogger("Logger");
public WindowsService()
{
ServiceName = "ExtractionManagerService";
InitializeComponent();
}
public static void Main()
{
log4net.Config.XmlConfigurator.Configure();
Run(new WindowsService());
}
protected override void OnStart(string[] args)
{
try
{
if (ServiceHost != null)
{
ServiceHost.Close();
}
var factory = new WindsorFactory();
var extractionManagerService =
factory.Windsor.Resolve<IExtractionManagerService>("IExtractionManagerService");
ServiceHost = new ServiceHost(extractionManagerService);
ServiceHost.AddServiceEndpoint(typeof(IExtractionManagerService),
Constants.BINDING, Constants.ADDRESS);
ServiceHost.Open();
Log.Debug("ExtractionManagerService started.");
}
catch (Exception e)
{
Log.Error(string.Format("Unable to start Extraction Manager
Service: {0}", e.Message), e);
throw;
}
}
protected override void OnStop()
{
if (ServiceHost == null) return;
try
{
ServiceHost.Close();
Log.Debug("ExtractionManagerService stopped.");
}
catch(Exception ex)
{
Log.Error(String.Format("Error closing
ExtractionManagerService {0}.", ex.Message), ex);
}
finally
{
ServiceHost = null;
}
}
}
}
namespace ExtractionManager.Service
{
public interface IWindsorFactory
{
IWindsorContainer Windsor { get; }
}
public class WindsorFactory : IWindsorFactory
{
public IWindsorContainer Windsor { get; private set; }
public WindsorFactory()
{
Windsor = new WindsorContainer();
Windsor.Install(new WindsorInstaller());
}
}
}
namespace ExtractionManager.Service
{
[ServiceBehavior(InstanceContextMode = InstanceContextMode.Single)]
public class ExtractionManagerService : IExtractionManagerService
{
private readonly IDBProxy _dbProxy;
private readonly ILogger _logger;
public ExtractionManagerService(IDBProxy dbProxy, ILogger logger)
{
_dbProxy = dbProxy;
var queuedJobs = _dbProxy.GetQueuedJobs();
_logger.Debug(String.Format("{0} jobs were extracting and need to be
reset.", queuedJobs.Count));
// additional code removed
_logger.Debug("Extraction Manager Service started.");
}
}
}
--
You received this message because you are subscribed to the Google Groups
"Castle Project Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/castle-project-users.
For more options, visit https://groups.google.com/groups/opt_out.