示例#1
0
        protected void Application_Start()
        {
            AreaRegistration.RegisterAllAreas();
            FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
            RouteConfig.RegisterRoutes(RouteTable.Routes);
            BundleConfig.RegisterBundles(BundleTable.Bundles);

            var remoteRazorLocationStore = new RemoteRazorLocationStore();

            remoteRazorLocationStore.LoadRemoteDataAsync("https://rawgit.com/ghstahl/asset-repo/master/aspnet-mvc5/views.json").GetAwaiter().GetResult();

            HostingEnvironment.RegisterVirtualPathProvider(new ViewPathProvider(remoteRazorLocationStore));

            var remoteStaticExternalSpaStore = new RemoteStaticExternalSpaStore(
                "https://rawgit.com/ghstahl/asset-repo/master/aspnet-mvc5/external.spa.config.json");
            var records = remoteStaticExternalSpaStore.GetRemoteDataAsync().GetAwaiter().GetResult();

            foreach (var spa in records.Spas)
            {
                remoteStaticExternalSpaStore.AddRecord(spa);
            }

            var builder = new ContainerBuilder();

            builder.RegisterControllers(typeof(MvcApplication).Assembly);
            builder.RegisterInstance(remoteStaticExternalSpaStore).As <IExternalSpaStore>();
            var container = builder.Build();

            DependencyResolver.SetResolver(new AutofacDependencyResolver(container));
        }
示例#2
0
        protected override void Load(ContainerBuilder builder)
        {
            // The generic ILogger<TCategoryName> service was added to the ServiceCollection by ASP.NET Core.
            // It was then registered with Autofac using the Populate method in ConfigureServices.
            builder.Register(c => new ValuesService(c.Resolve <ILogger <ValuesService> >()))
            .As <IValuesService>()
            .InstancePerLifetimeScope();
            builder.Register(c => new InMemorySimpleRedirectStore())
            .As <ISimpleRedirectorStore>()
            .SingleInstance();

            builder.RegisterType <LocalSettingsGlobalPathAuthorizeStore>()
            .As <IGlobalPathAuthorizeStore>()
            .SingleInstance();
            builder.RegisterType <LocalSettingsOptOutOptInAuthorizeStore>()
            .As <IOptOutOptInAuthorizeStore>()
            .SingleInstance();

            builder.RegisterType <OptOutOptInFilterProvider>()
            .As <IFilterProvider>()
            .SingleInstance();

            // register the global configuration root
            builder.RegisterType <GlobalConfigurationRoot>()
            .As <IConfigurationRoot>()
            .SingleInstance();

            // build external InMemoryStore
            var remoteStaticExternalSpaStore = new RemoteStaticExternalSpaStore(
                "https://rawgit.com/ghstahl/P7/master/src/WebApplication5/external.spa.config.json");
            var records = remoteStaticExternalSpaStore.GetRemoteDataAsync().GetAwaiter().GetResult();

            foreach (var spa in records.Spas)
            {
                remoteStaticExternalSpaStore.AddRecord(spa);
            }


            /*
             * remoteStaticExternalSpaStore.AddRecord(new ExternalSPARecord()
             * {
             *  Key = "Support",
             *  RequireAuth = false,
             *  RenderTemplate = "<div access_token={%{user.access_token}%}>Well Hello Support</div>"
             * });
             * remoteStaticExternalSpaStore.AddRecord(new ExternalSPARecord()
             * {
             *  Key = "admin",
             *  RequireAuth = true,
             *  RenderTemplate = "<div access_token={%{user.access_token}%}>Well Hello Admin</div>"
             * });
             */

            builder.Register(c => remoteStaticExternalSpaStore)
            .As <IExternalSPAStore>()
            .SingleInstance();
        }