protected override void ApplicationStartup(TinyIoCContainer nancy, IPipelines pipelines)
        {
            // Create Simple Injector container
            Container container = new Container();

            PackageExtensions.RegisterPackages(container, System.AppDomain.CurrentDomain.GetAssemblies());
            //container.Options.DefaultScopedLifestyle = new ExecutionContextScopeLifestyle();

            // Register application components here, e.g.:
            //container.Register(typeof(ICommandHandler<>), AppDomain.CurrentDomain.GetAssemblies());

            // Register Nancy modules.
            foreach (var nancyModule in this.Modules)
            {
                container.Register(nancyModule.ModuleType);
            }

            // Cross-wire Nancy abstractions that application components require (if any). e.g.:
            //container.Register(nancy.Resolve<IModelValidator>);

            // Check the container.
            container.Verify();

            // Hook up Simple Injector in the Nancy pipeline.
            nancy.Register(typeof(INancyModuleCatalog), new SimpleInjectorModuleCatalog(container));
            nancy.Register(typeof(INancyContextFactory), new Injection.SimpleInjectorScopedContextFactory(
                               container, nancy.Resolve <INancyContextFactory>()));

            rootProvider = container.GetInstance <IRootPathProvider>();
        }
        protected virtual void SetControllerFactory(PipelineArgs args)
        {
            var container = new Container();

            PackageExtensions.RegisterPackages(container, AppDomain.CurrentDomain.GetAssemblies().Where(a => a.FullName.StartsWith("SitecoreMVC."))); // you can customize this to what ever you need

            var simpleInjectorControllerFactory = new SimpleInjectorControllerFactory(container);
            var sitecoreControllerFactory       = new Sitecore.Mvc.Controllers.SitecoreControllerFactory(simpleInjectorControllerFactory);

            ControllerBuilder.Current.SetControllerFactory(sitecoreControllerFactory);
        }
Beispiel #3
0
        public static void Main(string[] args)
        {
            try
            {
                var cnt = new SimpleInjector.Container();
                PackageExtensions.RegisterPackages(cnt, System.AppDomain.CurrentDomain.GetAssemblies());

                //
                //var options = new OptionSet {
                //    { "instance=", "append a tag onto the instance name, to allow multiple services to run", (string r) => cfg.ApplicationInstanceId = r },
                //};
                //var test = options.Parse(args);

                HostFactory.Run(c =>
                {
                    var cfg = cnt.GetInstance <IConfiguration>();
                    c.UseSimpleInjector(cnt);

                    // TODO: Will need to change this to run as user later...
                    c.RunAsLocalSystem();
                    var instanceOverride   = cfg.ApplicationInstanceName;
                    var serviceDisplayName = string.Format("{0} - {1}", cfg.ApplicationName, instanceOverride);
                    var serviceName        = string.Format("{0} - {1}", cfg.ApplicationName, instanceOverride);
                    var serviceDescription = string.Format("{0} - {1}", cfg.ApplicationName, instanceOverride);

                    c.SetDisplayName(serviceDisplayName);
                    c.SetServiceName(serviceName);
                    c.SetDescription(serviceDescription);
                    c.EnableServiceRecovery(rc =>
                    {
                        rc.RestartService(1); // restart the service after 1 minute
                        rc.RestartService(2); // restart the service after 2 minute
                        rc.RestartService(3); // restart the service after 3 minute
                        rc.SetResetPeriod(1); // set the reset interval to one day
                    });
                    c.Service <ISecureBootstrapListenerService>(srv =>
                    {
                        srv.ConstructUsingSimpleInjector();
                        srv.WhenStarted((service) => service.Start());
                        srv.WhenStopped((service) => service.Stop());
                    });
                });
            }
            catch (Exception ex)
            {
                Console.WriteLine($"Exception: {ex.Message} at {ex.StackTrace}");
            }
        }