public TemplateTags(TemplateTags tags) { this.Title = tags.Title; this.Meta = new List <string>(tags.Meta); this.MetaNames = new Dictionary <string, string>(tags.MetaNames); this.MetaProperties = new Dictionary <string, string>(tags.MetaProperties); this.Head = new List <string>(tags.Head); this.Content = new List <string>(tags.Content); this.Body = new List <string>(tags.Body); }
public static TemplateTags AddDefaultTemplateTags(this TemplateTags tags, string title, string directlink = null, string signalR = null, bool addBootstrap = true, bool isDevelopment = false, bool nocache = false, bool hmr = false) { var min = isDevelopment ? "" : ".min"; if (directlink == null) { directlink = $"https://unpkg.com/[email protected]/dist/browser/directlink-react{min}.js"; } if (signalR == null) { signalR = $"https://unpkg.com/@aspnet/[email protected]/dist/browser/signalr{min}.js"; } var polyfill = $"https://cdn.polyfill.io/v2/polyfill{min}.js"; var jquery = $"https://cdnjs.cloudflare.com/ajax/libs/jquery/3.2.1/jquery{min}.js"; var reactVersion = "16.2.0"; tags.Title = title; if (addBootstrap) { tags.Head.AddLink("https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css", "sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm", "anonymous"); tags.Body .AddScript("https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.12.9/umd/popper.min.js", "sha384-ApNbgh9B+Y1QKtv3Rn7W3mgPxhU9K/ScQsAP7hUibX39j7fakFPskvXusvfa0b4Q", "anonymous") .AddScript("https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/js/bootstrap.min.js", "sha384-JZR6Spejh4U02d8jOt6vLEHfe/JQGiRRSQQxSfFWpi1MquVdAyjUar5+76PVCmYl", "anonymous"); } if (isDevelopment) { tags.Head .AddScript($"https://unpkg.com/react@{reactVersion}/umd/react.development.js") .AddScript($"https://unpkg.com/react-dom@{reactVersion}/umd/react-dom.development.js") .AddScript(jquery, "sha256-DZAnKJ/6XZ9si04Hgrsxu/8s717jcIzLy3oi35EouyE=", "anonymous", condition: addBootstrap); } else { tags.Head .AddScript($"https://unpkg.com/react@{reactVersion}/umd/react.production.min.js") .AddScript($"https://unpkg.com/react-dom@{reactVersion}/umd/react-dom.production.min.js") .AddScript(jquery, "sha256-hwg4gsxgFZhOsEEamdOYGBf13FyQuiTwlAQgxVSNgt4=", "anonymous", condition: addBootstrap); } tags.Head .AddScript(polyfill) .AddScript(signalR) .AddScript(directlink); if (nocache) { tags.Head.Add("<script>directlink.nocache = true;</script>"); } if (hmr) { tags.Head.Add("<script>directlink.hmr = true;</script>"); } return(tags); }
public static IServiceCollection AddDirectLink(this IServiceCollection services, Action <DirectLinkOptions> optionsSetupAction, Action <TemplateTags> tagsSetupAction = null, IEnumerable <Assembly> assemblies = null) { services.AddSignalR() .AddJsonProtocol(options => options.PayloadSerializerSettings = new JsonSerializerSettings { ContractResolver = new DefaultContractResolver() }); services.AddSingleton(typeof(DirectLinkOptionsProvider), provider => { var options = GetDefaultOptions(); options.NodeServicesOptions = new NodeServicesOptions(provider) { WatchFileExtensions = new[] { ".js" } }; options.DirectLinkOutputLogger = provider.GetService <ILoggerFactory>().CreateLogger("DirectLink.Core"); optionsSetupAction.Invoke(options); if (options.EntryType == null) { throw new InvalidOperationException("EntryType is null. You need to specify EntryType: services.AddDirectLink(options => {{ options.EntryType = typeof(...); }})"); } if (!typeof(IDirectLink <ViewModel>).IsAssignableFrom(options.EntryType)) { throw new InvalidOperationException("EntryType is not valid. You need to specify correct EntryType"); } return(new DirectLinkOptionsProvider(options)); }); services.AddSingleton <HotNodeServicesFactory>(); services.AddScoped(typeof(IHotNodeService), provider => provider.GetService <HotNodeServicesFactory>().GetHotNodeService()); if (assemblies == null) { assemblies = new[] { Assembly.GetEntryAssembly() }; } var types = assemblies.SelectMany(assembly => assembly.GetTypes()) .Where(type => typeof(IDirectLink <ViewModel>).IsAssignableFrom(type)) .ToArray(); foreach (var type in types) { services.AddScoped(type); } services.AddSingleton(typeof(IComponentsService), provider => new ComponentsService(types, provider.GetService <ILogger <ComponentsService> >(), provider.GetService <DirectLinkOptionsProvider>()) ); services.AddScoped <IRoutingService, RoutingService>(); var tags = new TemplateTags(); tagsSetupAction?.Invoke(tags); services.AddScoped(typeof(DirectLinkContext), provider => new DirectLinkContext { Tags = new TemplateTags(tags), Data = new Dictionary <string, object>() } ); return(services); }