public static IUnityContainer GetUnityContainer()
        {
            var helper    = new UnityHelper(GetAssembliesToLoad());
            var container = helper.Container;

            container.RegisterType <IUnitOfWork, UnitOfWork>();
            container = helper.BuildUnityContainer();
            return(container);
        }
Esempio n. 2
0
        public static IUnityContainer GetUnityContainer()
        {
            var helper    = new UnityHelper(GetAssembliesToLoad());
            var container = helper.Container;

            container.RegisterType <IUnitOfWork, UnitOfWork>(new PerHttpRequestLifetime());
            container.RegisterType <HttpContextBase, HttpContextWrapper>();
            container.RegisterType <HttpContext>(new InjectionFactory(c => HttpContext.Current));
            container = helper.BuildUnityContainer();
            return(container);
        }
Esempio n. 3
0
        public static void Register(HttpConfiguration configuration)
        {
            configuration.MapHttpAttributeRoutes();
            configuration.Services.Add(typeof(IExceptionLogger), new UnhandledExceptionLogger());
            configuration.Routes.MapHttpRoute("API Default", "_apis/{controller}/{id}",
                                              new { id = RouteParameter.Optional });

            var container = new UnityContainer();

            UnityHelper.BuildUnityContainer(container);
            configuration.DependencyResolver = new UnityResolver(container);
        }
Esempio n. 4
0
        //public static IUnityContainer Container { get; set; }

        public static void RegisterTypes(IUnityContainer container)
        {
            UnityHelper.BuildUnityContainer(container);

            UnityDependencyResolver.DependencyResolve(container);

            foreach (var task in container.ResolveAll <IUnityDependencyResolver>())
            {
                task.ResolveDependency(container);
            }
            // register all your components with the container here
            // it is NOT necessary to register your controllers

            // e.g. container.RegisterType<ITestService, TestService>();

            //DependencyResolver.SetResolver(new UnityDependencyResolver(container));
        }
Esempio n. 5
0
        /// <summary>
        ///     Registers the type mappings with the Unity container.
        /// </summary>
        /// <param name="container">The unity container to configure.</param>
        /// <remarks>
        ///     There is no need to register concrete types such as controllers or
        ///     API controllers (unless you want to change the defaults), as Unity
        ///     allows resolving a concrete type even if it was not previously
        ///     registered.
        /// </remarks>
        public static void RegisterTypes(IUnityContainer container)
        {
            UnityHelper.BuildUnityContainer(container);

            Core.Kernel.AmbientScope.UnityDependencyResolver.DependencyResolve(container);

            // container.RegisterType<IDbContextFactory, DefaultDbContextFactory>(new PerResolveLifetimeManager());

            foreach (var task in container.ResolveAll <IUnityDependencyResolver>())
            {
                task.ResolveDependency(container);
            }

            //  fetch info
            IUserDepartmentServices userDeptServices = (IUserDepartmentServices)container.Resolve(typeof(IUserDepartmentServices));

            userDeptServices.GetCachedUserDepartmentDtos();
        }
Esempio n. 6
0
        public void Configuration(IAppBuilder app)
        {
            AreaRegistration.RegisterAllAreas();
            System.Web.Http.GlobalConfiguration.Configure(WebApiConfig.Register);
            FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);

            // Start unity
            UnityHelper.InitialiseUnityContainer();

            // Make DB update to latest migration
            Database.SetInitializer(new MigrateDatabaseToLatestVersion <DataContext, Configuration>());

            // Set the rest of the Ioc
            UnityHelper.BuildUnityContainer();

            // Grab the container as we will need to use it
            var unityContainer = UnityHelper.Container;

            // Set Hangfire to use SQL Server and the connection string
            //GlobalConfiguration.Configuration.UseSqlServerStorage(@"Server=.\SQLExpress;database=OriginV;Trusted_Connection=True;");
            GlobalConfiguration.Configuration.UseSqlServerStorage(FacultyV3ENConfirguration.Instance.OriginContext);

            // Make hangfire use unity container
            GlobalConfiguration.Configuration.UseUnityActivator(unityContainer);

            // Add Hangfire
            // TODO - Do I need this dashboard?
            //app.UseHangfireDashboard();
            app.UseHangfireServer();

            // Get services needed
            var DataContext = unityContainer.Resolve <DataContext>();

            // Routes
            RouteConfig.RegisterRoutes(RouteTable.Routes);
            BundleConfig.RegisterBundles(BundleTable.Bundles);
            app.MapSignalR();
        }
Esempio n. 7
0
        public void Configuration(IAppBuilder app)
        {
            AreaRegistration.RegisterAllAreas();
            System.Web.Http.GlobalConfiguration.Configure(WebApiConfig.Register);
            FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);

            // Start unity
            UnityHelper.InitialiseUnityContainer();

            // Make DB update to latest migration
            Database.SetInitializer(new MigrateDatabaseToLatestVersion <MvcForumContext, Configuration>());

            // Set the rest of the Ioc
            UnityHelper.BuildUnityContainer();

            // Grab the container as we will need to use it
            var unityContainer = UnityHelper.Container;

            // Set Hangfire to use SQL Server and the connection string
            GlobalConfiguration.Configuration.UseSqlServerStorage(ForumConfiguration.Instance.MvcForumContext);

            // Make hangfire use unity container
            GlobalConfiguration.Configuration.UseUnityActivator(unityContainer);

            // Add Hangfire
            // TODO - Do I need this dashboard?
            //app.UseHangfireDashboard();
            app.UseHangfireServer();

            // Get services needed
            var mvcForumContext  = unityContainer.Resolve <IMvcForumContext>();
            var badgeService     = unityContainer.Resolve <IBadgeService>();
            var loggingService   = unityContainer.Resolve <ILoggingService>();
            var assemblyProvider = unityContainer.Resolve <IAssemblyProvider>();

            // Routes
            RouteConfig.RegisterRoutes(RouteTable.Routes);

            // If the same carry on as normal
            var logFileSize = ForumConfiguration.Instance.LogFileMaxSizeBytes;

            loggingService.Initialise(logFileSize > 100000 ? logFileSize : 100000);
            loggingService.Error("START APP");

            // Find the plugin, pipeline and badge assemblies
            var assemblies = assemblyProvider.GetAssemblies(ForumConfiguration.Instance.PluginSearchLocations).ToList();

            ImplementationManager.SetAssemblies(assemblies);

            // Do the badge processing
            try
            {
                badgeService.SyncBadges(assemblies);
                mvcForumContext.SaveChanges();
            }
            catch (Exception ex)
            {
                loggingService.Error($"Error processing badge classes: {ex.Message}");
            }

            var theme    = "Metro";
            var settings = mvcForumContext.Setting.FirstOrDefault();

            if (settings != null)
            {
                theme = settings.Theme;
            }

            // Set the view engine
            ViewEngines.Engines.Clear();
            ViewEngines.Engines.Add(new ForumViewEngine(theme));

            // Initialise the events
            EventManager.Instance.Initialize(loggingService, assemblies);

            // Finally trigger any Cron jobs
            RecurringJob.AddOrUpdate <RecurringJobService>(x => x.SendMarkAsSolutionReminders(), Cron.HourInterval(6), queue: "solutionreminders");
        }
Esempio n. 8
0
        public void Configuration(IAppBuilder app)
        {
            AreaRegistration.RegisterAllAreas();
            System.Web.Http.GlobalConfiguration.Configure(WebApiConfig.Register);
            FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);

            // Start unity
            UnityHelper.InitialiseUnityContainer(System.Web.Http.GlobalConfiguration.Configuration);

            // Make DB update to latest migration
            // Database.SetInitializer(new MigrateDatabaseToLatestVersion<MvcForumContext, Configuration>());

            // Set the rest of the Ioc
            UnityHelper.BuildUnityContainer();

            // Grab the container as we will need to use it
            var unityContainer = UnityHelper.Container;

            // Set Hangfire to use SQL Server and the connection string
            //GlobalConfiguration.Configuration.UseSqlServerStorage(ForumConfiguration.Instance.MvcForumContext);

            // Make hangfire use unity container
            //GlobalConfiguration.Configuration.UseUnityActivator(unityContainer);

            // Configure OWIN
            app.CreatePerOwinContext <MvcForumContext>(() => new MvcForumContext());
            app.CreatePerOwinContext <UserManager <IdentityUser> >(CreateManager);
            app.UseOAuthAuthorizationServer(new OAuthAuthorizationServerOptions
            {
                TokenEndpointPath         = new PathString("/oauth/token"),
                Provider                  = new AuthorizationProvider(new UnityDependencyResolver(unityContainer).GetService <IMembershipService>()),
                AccessTokenExpireTimeSpan = TimeSpan.FromMinutes(30),
                AllowInsecureHttp         = true,
            });
            app.UseOAuthBearerAuthentication(new OAuthBearerAuthenticationOptions());

            // Add Hangfire
            // TODO - Do I need this dashboard?
            //app.UseHangfireDashboard();
            //app.UseHangfireServer();

            // Get services needed
            var mvcForumContext     = unityContainer.Resolve <IMvcForumContext>();
            var loggingService      = unityContainer.Resolve <ILoggingService>();
            var assemblyProvider    = unityContainer.Resolve <IAssemblyProvider>();
            var localizationService = unityContainer.Resolve <ILocalizationService>();
            var cacheService        = unityContainer.Resolve <ICacheService>();

            ((IObjectContextAdapter)mvcForumContext).ObjectContext.Refresh(RefreshMode.StoreWins, mvcForumContext.LocaleStringResource);


            // Routes
            RouteConfig.RegisterRoutes(RouteTable.Routes);

            // If the same carry on as normal
            var logFileSize = ForumConfiguration.Instance.LogFileMaxSizeBytes;

            loggingService.Initialise(logFileSize > 100000 ? logFileSize : 100000);
            loggingService.Error("START APP");

            // Find the plugin, pipeline and badge assemblies
            var assemblies = assemblyProvider.GetAssemblies(ForumConfiguration.Instance.PluginSearchLocations).ToList();

            ImplementationManager.SetAssemblies(assemblies);

            var theme    = "Default";
            var settings = mvcForumContext.Setting.FirstOrDefault();

            if (settings != null)
            {
                theme = settings.Theme;
            }

            // Set the view engine
            ViewEngines.Engines.Clear();
            ViewEngines.Engines.Add(new ForumViewEngine(theme));

            // Initialise the events
            EventManager.Instance.Initialize(loggingService, assemblies);

            // Finally trigger any Cron jobs
            //RecurringJob.AddOrUpdate<RecurringJobService>(x => x.SendMarkAsSolutionReminders(), Cron.HourInterval(6),
            //    queue: "solutionreminders");
        }