public void Init() { var builder = new ContainerBuilder(); builder.RegisterComposablePartCatalog(new AssemblyCatalog(Assembly.GetAssembly(typeof(TestEntity)))); builder.RegisterComposablePartCatalog(new AssemblyCatalog(Assembly.GetAssembly(typeof(ITestEntityProxy)))); builder.RegisterType<EntityDomain>().As<IEntityDomain>(); builder.RegisterType<EntityRepository>().As<IEntityRepository>(); builder.RegisterType<MessageFactory>().As<IMessageFactory>(); builder.RegisterType<RakPeerInterface>().As<INetPeer>(); builder.RegisterType<EntityClusterNode>().As<IEntityClusterNode>(); builder.RegisterType<NullPersistanceProvider>().As<IPersistanceProvider>(); container = builder.Build(); }
private void LoadPlugins() { var builder = new ContainerBuilder(); var aggregateCatalog = new AggregateCatalog(); aggregateCatalog.Catalogs.Add(new DirectoryCatalog("Plugins", "TestApp.*.dll")); builder.RegisterComposablePartCatalog(aggregateCatalog); _container = builder.Build(); }
public void OnApplicationStarting(UmbracoApplicationBase umbracoApplication, ApplicationContext applicationContext) { var viewPaths = new List<string>() { "~/Views/{0}.cshtml", "~/Views/{0}/{1}.cshtml", "~/Views/Shared/{0}.cshtml", "~/Views/Partials/{0}.cshtml", "~/Views/Region/{0}.cshtml", "~/Views/Widget/{0}.cshtml" }; var catalog = new AggregateCatalog(); var curentAssembly = new AssemblyCatalog(Assembly.GetExecutingAssembly()); catalog.Catalogs.Add(curentAssembly); var builder = new ContainerBuilder(); builder.Register(c => UmbracoContext.Current).AsSelf(); builder.RegisterControllers(Assembly.GetExecutingAssembly()); builder.RegisterApiControllers(typeof(UmbracoApplication).Assembly); foreach (var path in Directory.EnumerateDirectories(AppDomain.CurrentDomain.BaseDirectory + "\\Plugins", "*Widget*", SearchOption.TopDirectoryOnly)) { catalog.Catalogs.Add(new DirectoryCatalog(path)); var pluginName = path.Split('\\'); viewPaths.Add(String.Format("~/Plugins/{0}/Views/{1}.cshtml", pluginName[pluginName.Length - 1], "{0}")); var pluginAssembly = Assembly.Load(pluginName[pluginName.Length - 1]); builder.RegisterControllers(pluginAssembly); //ToDo: Add routes to view engine for none umbraco ones (below errors with No Tempalte //RouteTable.Routes.MapRoute(pluginName[pluginName.Length - 1], "{controller}/{action}", new //{ // controller = pluginName[pluginName.Length - 1], // action = "RenderWidget", // id = UrlParameter.Optional //}); } ViewEngines.Engines.Add(new UmbracoToolboxViewEngine(viewPaths.ToArray())); builder.RegisterComposablePartCatalog(catalog); var container = builder.Build(); DependencyResolver.SetResolver(new AutofacDependencyResolver(container)); var resolver = new AutofacWebApiDependencyResolver(container); GlobalConfiguration.Configuration.DependencyResolver = resolver; }
public void Initialize() { var builder = new ContainerBuilder(); var types = new[] { typeof (ScriptHostFactory), typeof (FileSystem), typeof (PackageAssemblyResolver), typeof (PackageContainer), typeof (FilePreProcessor), typeof (ScriptPackResolver), typeof (NugetInstallationProvider), typeof (PackageInstaller) }; builder.RegisterTypes(types).AsImplementedInterfaces(); if (_debug) { builder.RegisterType<DebugScriptExecutor>().As<IScriptExecutor>(); builder.RegisterType<RoslynScriptDebuggerEngine>().As<IScriptEngine>(); } else { builder.RegisterType<ScriptExecutor>().As<IScriptExecutor>(); builder.RegisterType<RoslynScriptEngine>().As<IScriptEngine>(); } builder.RegisterType<ScriptServiceRoot>().As<ScriptServiceRoot>(); if (_shouldInitDrirectoryCatalog) { var scriptPath = Path.Combine(Environment.CurrentDirectory, "bin"); if (Directory.Exists(scriptPath)) { var catalog = new DirectoryCatalog(scriptPath); builder.RegisterComposablePartCatalog(catalog); } } _container = builder.Build(); _scriptServiceRoot = _container.Resolve<ScriptServiceRoot>(); }
public AppBootstrapper() { Assembly currentAssembly = Assembly.GetExecutingAssembly(); ContainerBuilder builder = new ContainerBuilder(); AggregateCatalog catalog = new AggregateCatalog(); catalog.Catalogs.Add(new AssemblyCatalog(currentAssembly)); builder.RegisterComposablePartCatalog(catalog); builder.RegisterAssemblyTypes(currentAssembly) .AsImplementedInterfaces(); // ReactiveIRC.Client builder.RegisterType<Client>() .As<IClient>() .Exported(x => x.As<IClient>()) .SingleInstance() ; // Veda.Storage builder.RegisterType<JsonStorage>() .As<IStorage>() .As<IOpenableStorage>() .Exported(x => x.As<IStorage>()) .Exported(x => x.As<IOpenableStorage>()) ; builder.Register((c, p) => new StorageManager(p.Named<String>("path"), p.Named<String>("extension"), p.Named<String>("globalFile"))) .As<IPluginStorageManager>() .As<IStorageManager>() .Exported(x => x.As<IPluginStorageManager>()) .Exported(x => x.As<IStorageManager>()) .SingleInstance() ; // Veda.Plugin builder.RegisterType<PluginManager>() .As<IPluginManager>() .Exported(x => x.As<IPluginManager>()) .SingleInstance() ; // Veda.Command builder.RegisterType<CommandParser>() .As<ICommandParser>() .Exported(x => x.As<ICommandParser>()) .SingleInstance() ; builder.RegisterType<CommandManager>() .As<ICommandManager>() .Exported(x => x.As<ICommandManager>()) .SingleInstance() ; // Veda.Authentication builder.RegisterType<AuthenticationManager>() .As<IAuthenticationManager>() .Exported(x => x.As<IAuthenticationManager>()) .SingleInstance() ; builder.RegisterType<BotUser>() .As<IBotUser>() .Exported(x => x.As<IBotUser>()) ; builder.RegisterType<BotGroup>() .As<IBotGroup>() .Exported(x => x.As<IBotGroup>()) ; // Veda.Authentication builder.RegisterType<PermissionManager>() .As<IPluginPermissionManager>() .As<IPermissionManager>() .Exported(x => x.As<IPluginPermissionManager>()) .Exported(x => x.As<IPermissionManager>()) .SingleInstance() ; // Veda builder.RegisterType<Bot>() .As<IBot>() .Exported(x => x.As<IBot>()) .SingleInstance() ; CompositionManager.ConfigureDependencies(builder, catalog); }
protected override IContainer CreateContainer() { var builder = new ContainerBuilder(); _logger.Debug("Registering runtime services"); builder.RegisterInstance<ILog>(_logger).Exported(x => x.As<ILog>()); builder.RegisterType(_scriptEngineType).As<IScriptEngine>().SingleInstance(); builder.RegisterType(_scriptExecutorType).As<IScriptExecutor>().SingleInstance(); builder.RegisterInstance(_console).As<IConsole>(); builder.RegisterType<ScriptServices>().SingleInstance(); RegisterOverrideOrDefault<IFileSystem>(builder, b => b.RegisterType<FileSystem>().As<IFileSystem>().SingleInstance()); RegisterOverrideOrDefault<IAssemblyUtility>(builder, b => b.RegisterType<AssemblyUtility>().As<IAssemblyUtility>().SingleInstance()); RegisterOverrideOrDefault<IPackageContainer>(builder, b => b.RegisterType<PackageContainer>().As<IPackageContainer>().SingleInstance()); RegisterOverrideOrDefault<IPackageAssemblyResolver>(builder, b => b.RegisterType<PackageAssemblyResolver>().As<IPackageAssemblyResolver>().SingleInstance()); RegisterOverrideOrDefault<IAssemblyResolver>(builder, b => b.RegisterType<AssemblyResolver>().As<IAssemblyResolver>().SingleInstance()); RegisterOverrideOrDefault<IScriptHostFactory>(builder, b => b.RegisterType<ScriptHostFactory>().As<IScriptHostFactory>().SingleInstance()); RegisterOverrideOrDefault<IFilePreProcessor>(builder, b => b.RegisterType<FilePreProcessor>().As<IFilePreProcessor>().SingleInstance()); RegisterOverrideOrDefault<IScriptPackResolver>(builder, b => b.RegisterType<ScriptPackResolver>().As<IScriptPackResolver>().SingleInstance()); RegisterOverrideOrDefault<IInstallationProvider>(builder, b => b.RegisterType<NugetInstallationProvider>().As<IInstallationProvider>().SingleInstance()); RegisterOverrideOrDefault<IPackageInstaller>(builder, b => b.RegisterType<PackageInstaller>().As<IPackageInstaller>().SingleInstance()); RegisterOverrideOrDefault<ScriptServices>(builder, b => b.RegisterType<ScriptServices>().SingleInstance()); var assemblyResolver = _initializationServices.GetAssemblyResolver(); if (_initDirectoryCatalog) { var currentDirectory = Environment.CurrentDirectory; var assemblies = assemblyResolver.GetAssemblyPaths(currentDirectory); var aggregateCatalog = new AggregateCatalog(); assemblies.Select(x => new AssemblyCatalog(x)).ToList() .ForEach(catalog => aggregateCatalog.Catalogs.Add(catalog)); builder.RegisterComposablePartCatalog(aggregateCatalog); } return builder.Build(); }
protected override IContainer CreateContainer() { var builder = new ContainerBuilder(); _log.Debug("Registering runtime services"); builder.RegisterInstance(this.LogProvider).Exported(x => x.As<ILogProvider>()); builder.RegisterType(_scriptEngineType).As<IScriptEngine>().SingleInstance(); builder.RegisterType(_scriptExecutorType).As<IScriptExecutor>().SingleInstance(); builder.RegisterType(_replType).As<IRepl>().SingleInstance(); builder.RegisterType<ScriptServices>().SingleInstance(); builder.RegisterType<Repl>().As<IRepl>().SingleInstance(); RegisterLineProcessors(builder); RegisterReplCommands(builder); RegisterOverrideOrDefault<IFileSystem>( builder, b => b.RegisterType<FileSystem>().As<IFileSystem>().SingleInstance()); RegisterOverrideOrDefault<IAssemblyUtility>( builder, b => b.RegisterType<AssemblyUtility>().As<IAssemblyUtility>().SingleInstance()); RegisterOverrideOrDefault<IPackageContainer>( builder, b => b.RegisterType<PackageContainer>().As<IPackageContainer>().SingleInstance()); RegisterOverrideOrDefault<IPackageAssemblyResolver>( builder, b => b.RegisterType<PackageAssemblyResolver>().As<IPackageAssemblyResolver>().SingleInstance()); RegisterOverrideOrDefault<IAssemblyResolver>( builder, b => b.RegisterType<AssemblyResolver>().As<IAssemblyResolver>().SingleInstance()); RegisterOverrideOrDefault<IScriptHostFactory>( builder, b => b.RegisterType<ScriptHostFactory>().As<IScriptHostFactory>().SingleInstance()); RegisterOverrideOrDefault<IFilePreProcessor>( builder, b => b.RegisterType<FilePreProcessor>().As<IFilePreProcessor>().SingleInstance()); RegisterOverrideOrDefault<IScriptPackResolver>( builder, b => b.RegisterType<ScriptPackResolver>().As<IScriptPackResolver>().SingleInstance()); RegisterOverrideOrDefault<IInstallationProvider>( builder, b => b.RegisterType<NugetInstallationProvider>().As<IInstallationProvider>().SingleInstance()); RegisterOverrideOrDefault<IPackageInstaller>( builder, b => b.RegisterType<PackageInstaller>().As<IPackageInstaller>().SingleInstance()); RegisterOverrideOrDefault<ScriptServices>( builder, b => b.RegisterType<ScriptServices>().SingleInstance()); RegisterOverrideOrDefault<IObjectSerializer>( builder, b => b.RegisterType<ObjectSerializer>().As<IObjectSerializer>().SingleInstance()); RegisterOverrideOrDefault<IConsole>( builder, b => b.RegisterInstance(_console)); RegisterOverrideOrDefault<IFileSystemMigrator>( builder, b => b.RegisterType<FileSystemMigrator>().As<IFileSystemMigrator>().SingleInstance()); RegisterOverrideOrDefault<IScriptLibraryComposer>( builder, b => b.RegisterType<ScriptLibraryComposer>().As<IScriptLibraryComposer>().SingleInstance()); RegisterOverrideOrDefault<IVisualStudioSolutionWriter>( builder, b => b.RegisterType<VisualStudioSolutionWriter>().As<IVisualStudioSolutionWriter>().SingleInstance()); if (_initDirectoryCatalog) { var fileSystem = _initializationServices.GetFileSystem(); var assemblies = _initializationServices.GetAssemblyResolver() .GetAssemblyPaths(fileSystem.GetWorkingDirectory(_scriptName)) .Where(assembly => ShouldLoadAssembly(fileSystem, _initializationServices.GetAssemblyUtility(), assembly)); var aggregateCatalog = new AggregateCatalog(); var assemblyLoadFailures = false; foreach (var assemblyPath in assemblies) { try { var catalog = new AssemblyCatalog(assemblyPath); // force the parts to be queried to catch any errors that would otherwise show up later catalog.Parts.ToList(); aggregateCatalog.Catalogs.Add(catalog); } catch (ReflectionTypeLoadException typeLoadEx) { assemblyLoadFailures = true; if (typeLoadEx.LoaderExceptions != null && typeLoadEx.LoaderExceptions.Any()) { foreach (var ex in typeLoadEx.LoaderExceptions.GroupBy(x => x.Message)) { _log.DebugFormat( "Failure loading assembly: {0}. Exception: {1}", assemblyPath, ex.First().Message); } } } catch (Exception ex) { assemblyLoadFailures = true; _log.DebugFormat("Failure loading assembly: {0}. Exception: {1}", assemblyPath, ex.Message); } } if (assemblyLoadFailures) { _log.Warn(string.IsNullOrEmpty(_scriptName) ? "Some assemblies failed to load. Launch with '-repl -loglevel debug' to see the details" : "Some assemblies failed to load. Launch with '-loglevel debug' to see the details"); } builder.RegisterComposablePartCatalog(aggregateCatalog); } return builder.Build(); }
protected override IContainer CreateContainer() { var builder = new ContainerBuilder(); this.Logger.Debug("Registering runtime services"); builder.RegisterInstance<ILog>(this.Logger).Exported(x => x.As<ILog>()); builder.RegisterType(_scriptEngineType).As<IScriptEngine>().SingleInstance(); builder.RegisterType(_scriptExecutorType).As<IScriptExecutor>().SingleInstance(); builder.RegisterType<ScriptServices>().SingleInstance(); RegisterLineProcessors(builder); RegisterOverrideOrDefault<IFileSystem>(builder, b => b.RegisterType<FileSystem>().As<IFileSystem>().SingleInstance()); RegisterOverrideOrDefault<IAssemblyUtility>(builder, b => b.RegisterType<AssemblyUtility>().As<IAssemblyUtility>().SingleInstance()); RegisterOverrideOrDefault<IPackageContainer>(builder, b => b.RegisterType<PackageContainer>().As<IPackageContainer>().SingleInstance()); RegisterOverrideOrDefault<IPackageAssemblyResolver>(builder, b => b.RegisterType<PackageAssemblyResolver>().As<IPackageAssemblyResolver>().SingleInstance()); RegisterOverrideOrDefault<IAssemblyResolver>(builder, b => b.RegisterType<AssemblyResolver>().As<IAssemblyResolver>().SingleInstance()); RegisterOverrideOrDefault<IScriptHostFactory>(builder, b => b.RegisterType<ScriptHostFactory>().As<IScriptHostFactory>().SingleInstance()); RegisterOverrideOrDefault<IFilePreProcessor>(builder, b => b.RegisterType<FilePreProcessor>().As<IFilePreProcessor>().SingleInstance()); RegisterOverrideOrDefault<IScriptPackResolver>(builder, b => b.RegisterType<ScriptPackResolver>().As<IScriptPackResolver>().SingleInstance()); RegisterOverrideOrDefault<IInstallationProvider>(builder, b => b.RegisterType<NugetInstallationProvider>().As<IInstallationProvider>().SingleInstance()); RegisterOverrideOrDefault<IPackageInstaller>(builder, b => b.RegisterType<PackageInstaller>().As<IPackageInstaller>().SingleInstance()); RegisterOverrideOrDefault<ScriptServices>(builder, b => b.RegisterType<ScriptServices>().SingleInstance()); RegisterOverrideOrDefault<IObjectSerializer>(builder, b => b.RegisterType<ObjectSerializer>().As<IObjectSerializer>().SingleInstance()); RegisterOverrideOrDefault<IConsole>(builder, b => b.RegisterInstance(_console)); var assemblyResolver = _initializationServices.GetAssemblyResolver(); if (_initDirectoryCatalog) { var fileSystem = _initializationServices.GetFileSystem(); var currentDirectory = fileSystem.GetWorkingDirectory(_scriptName); var assemblies = assemblyResolver.GetAssemblyPaths(currentDirectory); var aggregateCatalog = new AggregateCatalog(); bool assemblyLoadFailures = false; foreach (var assembly in assemblies) { try { var catalog = new AssemblyCatalog(assembly); catalog.Parts.ToList(); //force the Parts to be read aggregateCatalog.Catalogs.Add(catalog); } catch(Exception ex) { assemblyLoadFailures = true; Logger.DebugFormat("Failure loading assembly: {0}. Exception: {1}", assembly, ex.Message); } } if (assemblyLoadFailures) { if (_scriptName == null || _scriptName.Length == 0) Logger.Warn("Some assemblies failed to load. Launch with '-repl -loglevel debug' to see the details"); else Logger.Warn("Some assemblies failed to load. Launch with '-loglevel debug' to see the details"); } builder.RegisterComposablePartCatalog(aggregateCatalog); } return builder.Build(); }
static App() { var catalog = new AssemblyCatalog(typeof(App).Assembly); var builder = new ContainerBuilder(); builder.RegisterComposablePartCatalog(catalog); builder .Register(_ => App.Current) .As<Application>() .ExternallyOwned() .InstancePerLifetimeScope(); builder .Register(b => new MainViewModel()) .OnActivating(e => { e.Instance.StartCommand = e.Context.Resolve<StartCommand>(); e.Instance.StopCommand = e.Context.Resolve<StopCommand>(); e.Instance.SearchCommand = e.Context.Resolve<SearchCommand>(); }) .AsSelf() .InstancePerLifetimeScope(); builder .Register(b => YouTrackManager.GetConnection("youtrack.neveling.net", "testuser", "testuser")) .As<IConnection>() .InstancePerLifetimeScope(); builder .Register(b=>new IssueManagement(b.Resolve<IConnection>())) .AsSelf() .InstancePerLifetimeScope(); builder .RegisterType(typeof (YouTrackRepository)) .As(typeof(IRepository<string, IRepositoryPayload>)) .InstancePerLifetimeScope(); builder .RegisterType<YouTrackPayload>() .OnActivated(e=>e.Instance.Repository = e.Context.Resolve<IRepository<string, IRepositoryPayload>>()) .As<IRepositoryPayload>() .InstancePerDependency(); builder .RegisterType<StartCommand>() .OnActivated(e => { e.Instance.MainViewModel = e.Context.Resolve<MainViewModel>(); e.Instance.StartEventFactory = () => new TrakkrEventViewModel { Type = EventType.Start, Timestamp = DateTime.Now, Payload = Container.Resolve<IRepositoryPayload>() }; }) .AsSelf() .InstancePerLifetimeScope(); builder .RegisterType<StopCommand>() .OnActivated(e => { e.Instance.MainViewModel = e.Context.Resolve<MainViewModel>(); e.Instance.StopEventFactory = () => new TrakkrEventViewModel { Type = EventType.Stop, Timestamp = DateTime.Now, Payload = Container.Resolve<IRepositoryPayload>() }; }) .AsSelf() .InstancePerLifetimeScope(); builder .RegisterType<SearchCommand>() .OnActivated(e => { e.Instance.MainViewModel = e.Context.Resolve<MainViewModel>(); e.Instance.Repositroy = e.Context.Resolve<IRepository<string, IRepositoryPayload>>(); }) .AsSelf() .InstancePerLifetimeScope(); Container = builder.Build(); }
protected override void Load(ContainerBuilder builder) { var catalog = new TypeCatalog(typeof(GitSourceControlProvider)); builder.RegisterComposablePartCatalog(catalog); }
void IApplicationEventHandler.OnApplicationStarted(UmbracoApplicationBase umbracoApplication, ApplicationContext applicationContext) { //set up MEF to look for plugins in the /bin/plugins folder string codeBase = Assembly.GetExecutingAssembly().CodeBase; UriBuilder uri = new UriBuilder(codeBase); string path = Uri.UnescapeDataString(uri.Path); string exeLocation=Path.GetDirectoryName(path); string pluginPath = Path.Combine(exeLocation, "plugins"); var pluginCatalog = new DirectoryCatalog(pluginPath); var builder = new ContainerBuilder(); //register all controllers found in this assembly builder.RegisterControllers(typeof(CustomerPortalExtensionsApplication).Assembly); //add "internal" dependencies via Autofac builder.RegisterType<ContactRepository>().As<IContactRepository>(); builder.RegisterType<ContactSecondaryRepository>().As<IContactSecondaryRepository>(); builder.RegisterType<ContactAuthenticationHandler>().As<IContactAuthenticationHandler>(); builder.RegisterType<DefaultContactSynchroniser>().As<IContactSynchroniser>(); builder.RegisterType<Configuration>().As<IConfigurationService>(); builder.RegisterType<ContactService>().As<IContactService>(); builder.RegisterType<MailChimpEmailSubscriptionConnector>().As<IEmailSubscriptionConnector>(); builder.RegisterType<OrderRepository>().As<IOrderRepository>(); builder.RegisterType<DiscountHandlerFactory>().As<IDiscountHandlerFactory>(); builder.RegisterType<EcommerceService>().As<IEcommerceService>(); builder.RegisterType<OrderCoordinator>().As<IOrderCoordinator>(); builder.RegisterType<ShippingHandlerFactory>().As<IShippingHandlerFactory>(); builder.RegisterType<ProductRepository>().As<IProductRepository>(); builder.RegisterType<VoucherRepository>().As<IVoucherRepository>(); builder.RegisterType<LocationHandlerFactory>().As<ILocationHandlerFactory>(); builder.RegisterType<LocationHandler>().As<ILocationHandler>(); builder.RegisterType<OrderQueueService>().As<IOrderQueueService>(); builder.RegisterType<EmailSubscriptionsService>().As<IEmailSubscriptionsService>(); builder.RegisterType<OrderQueue>().As<IOrderQueue>(); builder.RegisterType<BespokePricingHandlerFactory>().As<IBespokePricingHandlerFactory>(); builder.RegisterType<AdditionalQueueProcessingHandlerFactory>() .As<IAdditionalQueueProcessingHandlerFactory>(); builder.RegisterType<Database>() .InstancePerHttpRequest() .WithParameter("connectionString", ConfigurationManager.ConnectionStrings["umbracoDbDSN"].ConnectionString) .WithParameter("providerName", "System.Data.SqlClient"); //add in "exeternal" dependencies via MEF builder.RegisterComposablePartCatalog(pluginCatalog); var container = builder.Build(); DependencyResolver.SetResolver(new AutofacDependencyResolver(container)); }