/// <summary> /// Add uSync to the site. /// </summary> public static IUmbracoBuilder AdduSync(this IUmbracoBuilder builder, Action <uSyncSettings> defaultOptions = default) { // if the uSyncConfig Service is registred then we assume this has been added before so we don't do it again. if (builder.Services.FirstOrDefault(x => x.ServiceType == typeof(uSyncConfigService)) != null) { return(builder); } // load up the settings. var options = builder.Services.AddOptions <uSyncSettings>() .Bind(builder.Config.GetSection(uSync.Configuration.ConfigSettings)); if (defaultOptions != default) { options.Configure(defaultOptions); } options.ValidateDataAnnotations(); // default handler options, other people can load their own names handler options and // they can be used throughout uSync (so complete will do this). var handlerOptiosn = builder.Services.Configure <uSyncHandlerSetSettings>(uSync.Sets.DefaultSet, builder.Config.GetSection(uSync.Configuration.ConfigDefaultSet)); // Setup uSync core. builder.AdduSyncCore(); // Setup the back office. builder.Services.AddSingleton <uSyncEventService>(); builder.Services.AddSingleton <uSyncConfigService>(); builder.Services.AddSingleton <SyncFileService>(); builder.WithCollectionBuilder <SyncHandlerCollectionBuilder>() .Add(() => builder.TypeLoader.GetTypes <ISyncHandler>()); builder.Services.AddSingleton <SyncHandlerFactory>(); builder.Services.AddSingleton <uSyncService>(); builder.Services.AddSingleton <CacheLifecycleManager>(); // first boot should happen before any other bits of uSync export on a blank site. builder.AdduSyncFirstBoot(); // register for the notifications builder.AddNotificationHandler <ServerVariablesParsingNotification, uSyncServerVariablesHandler>(); builder.AddNotificationHandler <UmbracoApplicationStartedNotification, uSyncApplicationStartingHandler>(); builder.AddHandlerNotifications(); builder.Services.AddSingleton <uSyncHubRoutes>(); builder.Services.AddSignalR(); builder.Services.AdduSyncSignalR(); builder.Services.AddAuthorization(o => CreatePolicies(o)); return(builder); }