예제 #1
0
        protected void Application_Start()
        {
            SourceLocator.GetInstance().ScanFolder(HttpContext.Current.Server.MapPath("~\\bin"));
            var sources = MatConfigurationSection.GetSettings().Sources.AsEnumerable<ISourceSettings>();
            SourceContainer.CreateInstanceIfNotExists(sources);

            AreaRegistration.RegisterAllAreas();

            FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
            RouteConfig.RegisterRoutes(RouteTable.Routes);
            BundleConfig.RegisterBundles(BundleTable.Bundles);

            GlobalConfiguration.Configuration.Formatters.JsonFormatter.SerializerSettings.ContractResolver = new SignalRContractResolver(); ;
            var serializer = new JsonNetSerializer(GlobalConfiguration.Configuration.Formatters.JsonFormatter.SerializerSettings);
            GlobalHost.DependencyResolver.Register(typeof(IJsonSerializer), () => serializer);

            MediaTimer.Start();
        }
예제 #2
0
        public static void PreAppStart()
        {
            if (HostingEnvironment.InClientBuildManager)
            {
                // If we're in the VS app domain then do nothing
                return;
            }

            var kernel = new StandardKernel();

            kernel.Bind<JabbrContext>()
                .To<JabbrContext>()
                .InRequestScope();

            kernel.Bind<IJabbrRepository>()
                .To<PersistedRepository>()
                .InRequestScope();

            kernel.Bind<IChatService>()
                  .To<ChatService>()
                  .InRequestScope();

            kernel.Bind<ICryptoService>()
                .To<CryptoService>()
                .InSingletonScope();

            kernel.Bind<IResourceProcessor>()
                .To<ResourceProcessor>()
                .InSingletonScope();

            kernel.Bind<IApplicationSettings>()
                  .To<ApplicationSettings>()
                  .InSingletonScope();

            kernel.Bind<IVirtualPathUtility>()
                  .To<VirtualPathUtilityWrapper>();

            kernel.Bind<IJavaScriptMinifier>()
                  .To<AjaxMinMinifier>()
                  .InSingletonScope();

            kernel.Bind<ICache>()
                  .To<AspNetCache>()
                  .InSingletonScope();

            var serializer = new JsonNetSerializer(new JsonSerializerSettings
            {
                DateFormatHandling = DateFormatHandling.MicrosoftDateFormat
            });

            kernel.Bind<IJsonSerializer>()
                  .ToConstant(serializer);

            Kernel = kernel;

            var resolver = new NinjectDependencyResolver(kernel);

            var host = new Host(resolver);
            host.Configuration.KeepAlive = TimeSpan.FromSeconds(30);

            RouteTable.Routes.MapHubs(resolver);

            // Perform the required migrations
            DoMigrations();

            // Start the sweeper
            var repositoryFactory = new Func<IJabbrRepository>(() => kernel.Get<IJabbrRepository>());
            _timer = new Timer(_ => Sweep(repositoryFactory, resolver), null, _sweepInterval, _sweepInterval);

            SetupErrorHandling();

            ClearConnectedClients(repositoryFactory());
            SetupRoutes(kernel);
            SetupWebApi(kernel);
        }
예제 #3
0
        protected void Application_Start()
        {
            AreaRegistration.RegisterAllAreas();

            RegisterGlobalFilters(GlobalFilters.Filters);
            RegisterRoutes(RouteTable.Routes);

            var builder = new ContainerBuilder();

            string busEndPointSetting = ConfigurationManager.AppSettings["setting_name_BusEndPointUri"];
            string dbSetting = ConfigurationManager.AppSettings["setting_name_loveboat.db"];
            string busEndPoint = ConfigurationManager.AppSettings[busEndPointSetting];
            string db = ConfigurationManager.AppSettings[dbSetting];

            builder.RegisterModule(new EasyNetQModule(busEndPoint));
            builder.RegisterModule(new EventStoreModule(db));
            builder.RegisterModule(new MongoModule(db));

            builder.RegisterModule(new RepositoryModule(typeof (EventRepository<>),
                                                        typeof (IEventRepository<>)));
            builder.RegisterModule(new RepositoryModule(typeof (DtoRepository<>), typeof (IDtoRepository<>)));

            builder.RegisterType<ViewModelEventDispatcher>().As<IViewModelEventDispatcher>();

            builder.RegisterControllers(Assembly.GetExecutingAssembly());

            builder.Register(context => { return GlobalHost.DependencyResolver.Resolve<IConnectionManager>(); }).As<IConnectionManager>();

            var settings = new JsonSerializerSettings();
            settings.ContractResolver = new SignalRContractResolver();
            var serializer = new JsonNetSerializer(settings);
            GlobalHost.DependencyResolver.Register(typeof (IJsonSerializer), () => serializer);

            IContainer container = builder.Build();

            //GlobalHost.DependencyResolver = new Configuration.AutofacDependencyResolver(container);

            DependencyResolver.SetResolver(new AutofacDependencyResolver(container));

            try
            {
                //need to make this registration stuff dynamic
                MessageHost.RegisterMessageHandlers(container,
                                                    new MessageRegistration
                                                        <ReplayEventStoreCommand, ReplayEventStoreCommandHandler>(),
                                                    new MessageRegistration<ArrivalCommand, ArrivalCommandHandler>(),
                                                    new MessageRegistration<DepartureCommand, DepartureCommandHandler>(),
                                                    new MessageRegistration
                                                        <ShipCreatedCommand, ShipCreatedCommandHandler>(),
                                                    new MessageRegistration<ExplodingCommand, ExplodedCommandHandler>()
                    );

                MessageHost.RegisterMessageHandlers(container,
                                                    new MessageRegistration<ArrivedEvent, ArrivalEventHandler>(),
                                                    new MessageRegistration<DepartedEvent, DepartedEventHandler>(),
                                                    new MessageRegistration<ShipCreatedEvent, ShipCreatedEventHandler>(),
                                                    new MessageRegistration<ExplodedEvent, ExplodedEventHandler>()
                    );

                MessageHost.RegisterMessageHandlers(container,
                                                    new MessageRegistration
                                                        <ViewModelUpdatedEvent<ShipViewModel>,
                                                        ViewModelUpdatedEventHandler<ShipViewModel>>()
                    );
            }
            catch(Exception ex)
            {
                throw new Exception(busEndPoint, ex);
            }

            //register an update handler for each view model type... preferably dynamically
        }
예제 #4
0
        public static void PreAppStart()
        {
            if (HostingEnvironment.InClientBuildManager)
            {
                // If we're in the VS app domain then do nothing
                return;
            }

            var kernel = new StandardKernel();

            kernel.Bind<JabbrContext>()
                .To<JabbrContext>()
                .InRequestScope();

            kernel.Bind<IJabbrRepository>()
                .To<PersistedRepository>()
                .InRequestScope();

            kernel.Bind<IChatService>()
                  .To<ChatService>()
                  .InRequestScope();

            kernel.Bind<IIdentityLinker>()
                  .To<IdentityLinker>()
                  .InRequestScope();

            kernel.Bind<ICryptoService>()
                .To<CryptoService>()
                .InSingletonScope();

            kernel.Bind<IResourceProcessor>()
                .To<ResourceProcessor>()
                .InSingletonScope();

            kernel.Bind<IApplicationSettings>()
                  .To<ApplicationSettings>()
                  .InSingletonScope();

            kernel.Bind<IVirtualPathUtility>()
                  .To<VirtualPathUtilityWrapper>();

            kernel.Bind<IJavaScriptMinifier>()
                  .To<AjaxMinMinifier>()
                  .InSingletonScope();

            kernel.Bind<ICache>()
                  .To<AspNetCache>()
                  .InSingletonScope();

            var serializer = new JsonNetSerializer(new JsonSerializerSettings
            {
                DateFormatHandling = DateFormatHandling.MicrosoftDateFormat
            });

            kernel.Bind<IJsonSerializer>()
                  .ToConstant(serializer);

            Kernel = kernel;
        }
예제 #5
0
        /// <summary>
        /// Load your modules or register your services here!
        /// </summary>
        /// <param name="kernel">The kernel.</param>
        private static void RegisterServices(IKernel kernel)
        {
            kernel.Bind<JabbrContext>()
                .To<JabbrContext>()
                .InRequestScope();

            kernel.Bind<IJabbrRepository>()
                .To<PersistedRepository>()
                .InRequestScope();

            kernel.Bind<IChatService>()
                  .To<ChatService>()
                  .InRequestScope();

            kernel.Bind<ICryptoService>()
                .To<CryptoService>()
                .InSingletonScope();

            kernel.Bind<IResourceProcessor>()
                .To<ResourceProcessor>()
                .InSingletonScope();

            kernel.Bind<IApplicationSettings>()
                  .To<ApplicationSettings>()
                  .InSingletonScope();

            kernel.Bind<IVirtualPathUtility>()
                  .To<VirtualPathUtilityWrapper>();

            kernel.Bind<IJavaScriptMinifier>()
                  .To<AjaxMinMinifier>()
                  .InSingletonScope();

            kernel.Bind<ICache>()
                  .To<AspNetCache>()
                  .InSingletonScope();

            var serializer = new JsonNetSerializer(new JsonSerializerSettings
            {
                DateFormatHandling = DateFormatHandling.MicrosoftDateFormat
            });

            kernel.Bind<IJsonSerializer>()
                  .ToConstant(serializer);

            var resolver = new NinjectDependencyResolver(kernel);

            var host = new Host(resolver);
            host.Configuration.KeepAlive = TimeSpan.FromSeconds(30);

            RouteTable.Routes.MapHubs(resolver);

            var repositoryFactory = new Func<IJabbrRepository>(() => kernel.Get<IJabbrRepository>());
            _timer = new Timer(_ => Sweep(repositoryFactory, resolver), null, _sweepInterval, _sweepInterval);

            GlobalHost.DependencyResolver = new SignalR.Ninject.NinjectDependencyResolver(kernel);

            SetupErrorHandling();

            ClearConnectedClients(repositoryFactory());
            SetupRoutes(kernel);
            SetupWebApi(kernel);
        }