public static void AssembliesFromApplicationBaseDirectory(this IAssemblyScanner scanner, Predicate <Assembly> assemblyFilter) { var baseDirectory = AppDomain.CurrentDomain.BaseDirectory; scanner.AssembliesFromPath(baseDirectory, assemblyFilter); var binPath = AppDomain.CurrentDomain.SetupInformation.PrivateBinPath; if (Directory.Exists(binPath)) { scanner.AssembliesFromPath(binPath, assemblyFilter); } }
public static void ScanPluginDirectory(this IAssemblyScanner scanner, Registry registry) { try { var cfg = ConfigurationManager.AppSettings["app:plugin-path"]; if (string.IsNullOrWhiteSpace(cfg)) { return; } var pluginsDirectory = Path.GetFullPath(cfg); if (!Directory.Exists(pluginsDirectory)) { return; } scanner.AssembliesFromPath(pluginsDirectory); scanner.LookForRegistries(); Type structureMapCheck = typeof(IServicePlugin); var assemblies = FindAssemblies(pluginsDirectory); foreach (var assembly in assemblies) { foreach (var type in assembly.GetExportedTypes().Where(a => !a.IsAbstract)) { if (!structureMapCheck.IsAssignableFrom(type)) { continue; } var interfaces = type.GetInterfaces(); foreach (var item in interfaces) { if (item == structureMapCheck) { continue; } registry.For(item).Use(type); } var baseType = type.BaseType; if (baseType == null || !baseType.IsAbstract) { continue; } registry.For(baseType).Use(type); } } } catch (Exception e) { var msg = e.Message; } }
private void DoScan(IAssemblyScanner assemblyScanner) { // Always create concrete instances based on usual DI naming // convention // i.e. Search for class name "Concrete" when "IConcrete" is // requested. assemblyScanner.WithDefaultConventions(); // Scan all assemblies, including the one executing. assemblyScanner.AssembliesFromPath(this.executingAssemblyLocation); }
/// <summary> /// Include all assemblies from the bin\ext directory into the scanning operation /// </summary> /// <param name="scanner"></param> public static void ExtensionAssemblies(this IAssemblyScanner scanner) { var extensionDir = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, ExtensionsBinPath); // based on the build configuration (Debug/Release), we end up with bin/ext or bin/<config>/ext if (!Directory.Exists(extensionDir)) { extensionDir = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, ExtenstionsDirName); } if (Directory.Exists(extensionDir)) { scanner.AssembliesFromPath(extensionDir, IsExtensionAssembly); // TODO: implement FindExtensibleRegistryInstancesScanner // scanner.With(new FindExtensibleRegistryInstancesScanner()); } }
private void Scan(IAssemblyScanner scanner) { scanner.TheCallingAssembly(); scanner.SingleImplementationsOfInterface(); scanner.WithDefaultConventions(); // Copy all plugins to the /bin/Plugins folder CopyPlugins(); // Scan plugins foreach (string subDirectory in Directory.GetDirectories(_applicationSettings.PluginsBinPath)) { scanner.AssembliesFromPath(subDirectory); } // UserServiceBase is scanned below // Scan for TextPlugins scanner.AddAllTypesOf <TextPlugin>(); // Scan for SpecialPages scanner.AddAllTypesOf <SpecialPagePlugin>(); // The pluginfactory scanner.AddAllTypesOf <IPluginFactory>(); // Config, repository, context scanner.AddAllTypesOf <ApplicationSettings>(); scanner.AddAllTypesOf <IRepository>(); scanner.AddAllTypesOf <IUserContext>(); // Services and services scanner.AddAllTypesOf <ServiceBase>(); scanner.AddAllTypesOf <IPageService>(); scanner.AddAllTypesOf <IActiveDirectoryProvider>(); scanner.AddAllTypesOf <UserServiceBase>(); // Text parsers scanner.AddAllTypesOf <MarkupConverter>(); scanner.AddAllTypesOf <CustomTokenParser>(); // MVC Related scanner.AddAllTypesOf <Roadkill.Core.Mvc.Controllers.Api.ApiControllerBase>(); scanner.AddAllTypesOf <Roadkill.Core.Mvc.Controllers.ControllerBase>(); scanner.AddAllTypesOf <UserViewModel>(); scanner.AddAllTypesOf <SettingsViewModel>(); scanner.AddAllTypesOf <AttachmentRouteHandler>(); scanner.AddAllTypesOf <ISetterInjected>(); scanner.AddAllTypesOf <IAuthorizationAttribute>(); scanner.AddAllTypesOf <RoadkillLayoutPage>(); scanner.AddAllTypesOf(typeof(RoadkillViewPage <>)); scanner.ConnectImplementationsToTypesClosing(typeof(RoadkillViewPage <>)); // Emails scanner.AddAllTypesOf <SignupEmail>(); scanner.AddAllTypesOf <ResetPasswordEmail>(); // Cache scanner.AddAllTypesOf <ListCache>(); scanner.AddAllTypesOf <PageViewModelCache>(); // Export scanner.AddAllTypesOf <WikiExporter>(); }
private void ScanTypes(IAssemblyScanner scanner) { scanner.TheCallingAssembly(); scanner.AssembliesFromApplicationBaseDirectory(assembly => assembly.FullName.Contains("Roadkill")); scanner.SingleImplementationsOfInterface(); scanner.WithDefaultConventions(); // Scan plugins: this includes everything e.g repositories, UserService, FileService TextPlugins CopyPlugins(ApplicationSettings); foreach (string subDirectory in Directory.GetDirectories(ApplicationSettings.PluginsBinPath)) { scanner.AssembliesFromPath(subDirectory); } // Plugins scanner.With(new AbstractClassConvention <TextPlugin>()); scanner.With(new AbstractClassConvention <SpecialPagePlugin>()); scanner.AddAllTypesOf <IPluginFactory>(); // Config, context scanner.AddAllTypesOf <ApplicationSettings>(); scanner.AddAllTypesOf <IUserContext>(); // Repositories scanner.AddAllTypesOf <ISettingsRepository>(); scanner.AddAllTypesOf <IUserRepository>(); scanner.AddAllTypesOf <IPageRepository>(); // Services scanner.With(new AbstractClassConvention <UserServiceBase>()); scanner.AddAllTypesOf <IPageService>(); scanner.AddAllTypesOf <ISearchService>(); scanner.AddAllTypesOf <ISettingsService>(); scanner.AddAllTypesOf <IActiveDirectoryProvider>(); scanner.AddAllTypesOf <IFileService>(); scanner.AddAllTypesOf <IInstallationService>(); // Text parsers scanner.AddAllTypesOf <MarkupConverter>(); scanner.AddAllTypesOf <CustomTokenParser>(); // MVC Related scanner.AddAllTypesOf <UserViewModel>(); scanner.AddAllTypesOf <SettingsViewModel>(); scanner.AddAllTypesOf <AttachmentRouteHandler>(); scanner.AddAllTypesOf <ISetterInjected>(); scanner.AddAllTypesOf <IAuthorizationAttribute>(); scanner.AddAllTypesOf <RoadkillLayoutPage>(); scanner.AddAllTypesOf(typeof(RoadkillViewPage <>)); scanner.ConnectImplementationsToTypesClosing(typeof(RoadkillViewPage <>)); // Emails scanner.AddAllTypesOf <SignupEmail>(); scanner.AddAllTypesOf <ResetPasswordEmail>(); // Cache scanner.AddAllTypesOf <ListCache>(); scanner.AddAllTypesOf <PageViewModelCache>(); // Export scanner.AddAllTypesOf <WikiExporter>(); // Controllers scanner.AddAllTypesOf <IRoadkillController>(); scanner.AddAllTypesOf <ControllerBase>(); scanner.AddAllTypesOf <ApiController>(); scanner.AddAllTypesOf <ConfigurationTesterController>(); }
private void Scan(IAssemblyScanner scanner) { scanner.TheCallingAssembly(); scanner.SingleImplementationsOfInterface(); scanner.WithDefaultConventions(); // Copy all plugins to the /bin/Plugins folder CopyPlugins(); // Scan plugins foreach (string subDirectory in Directory.GetDirectories(_applicationSettings.PluginsBinPath)) { scanner.AssembliesFromPath(subDirectory); } // UserServiceBase is scanned below // Scan for TextPlugins scanner.AddAllTypesOf<TextPlugin>(); // Scan for SpecialPages scanner.AddAllTypesOf<SpecialPagePlugin>(); // The pluginfactory scanner.AddAllTypesOf<IPluginFactory>(); // Config, repository, context scanner.AddAllTypesOf<ApplicationSettings>(); scanner.AddAllTypesOf<IRepository>(); scanner.AddAllTypesOf<IUserContext>(); // Services and services scanner.AddAllTypesOf<ServiceBase>(); scanner.AddAllTypesOf<IPageService>(); scanner.AddAllTypesOf<IActiveDirectoryProvider>(); scanner.AddAllTypesOf<UserServiceBase>(); scanner.AddAllTypesOf<IFileService>(); // Text parsers scanner.AddAllTypesOf<MarkupConverter>(); scanner.AddAllTypesOf<CustomTokenParser>(); // MVC Related scanner.AddAllTypesOf<Roadkill.Core.Mvc.Controllers.Api.ApiControllerBase>(); scanner.AddAllTypesOf<Roadkill.Core.Mvc.Controllers.ControllerBase>(); scanner.AddAllTypesOf<UserViewModel>(); scanner.AddAllTypesOf<SettingsViewModel>(); scanner.AddAllTypesOf<AttachmentRouteHandler>(); scanner.AddAllTypesOf<ISetterInjected>(); scanner.AddAllTypesOf<IAuthorizationAttribute>(); scanner.AddAllTypesOf<RoadkillLayoutPage>(); scanner.AddAllTypesOf(typeof(RoadkillViewPage<>)); scanner.ConnectImplementationsToTypesClosing(typeof(RoadkillViewPage<>)); // Emails scanner.AddAllTypesOf<SignupEmail>(); scanner.AddAllTypesOf<ResetPasswordEmail>(); // Cache scanner.AddAllTypesOf<ListCache>(); scanner.AddAllTypesOf<PageViewModelCache>(); // Export scanner.AddAllTypesOf<WikiExporter>(); }
public static void AssembliesFromPath(this IAssemblyScanner scanner, string path) { scanner.AssembliesFromPath(path, a => true); }