protected override void CopyDependenciesToDirectoryAndInitializeContainer(string path) { File.Copy(Path.Combine(Environment.CurrentDirectory, "Spring.Core.dll"), Path.Combine(Path.GetDirectoryName(path), "Spring.Core.dll"), true); ConfigurableInjection.InitializeContainer(ContextRegistry.GetContext()); }
public static IKernel RegisterKernel(INinjectModule[] injectModules) { Kernel = new StandardKernel(injectModules); Kernel.Components.Add <IInjectionHeuristic, PropertyInjectionHeuristic>(); ConfigurableInjection.InitializeContainer(Kernel); return(Kernel); }
public void Setup() { IKernel kernel = new StandardKernel(); kernel.Components.Add <IInjectionHeuristic, PropertyInjectionHeuristic>(); kernel.Bind <IService>().To <Service>().WithConstructorArgument("injectedValue", 5); ConfigurableInjection.InitializeContainer(kernel); }
public void Setup() { var builder = new ContainerBuilder(); builder.RegisterType <Service>().As <IService>() .WithParameter("injectedValue", 5); ConfigurableInjection.InitializeContainer(builder.Build()); }
public void SpringServiceIsInjected() { ConfigurableInjection.InitializeContainer(ContextRegistry.GetContext()); var entity = new Entity(5); Assert.IsNotNull(entity.InjectedService); Assert.IsInstanceOf(typeof(Service), entity.InjectedService); // refer to springObjects.xml to see Service and Entity classes configuration Assert.AreEqual(25, entity.InjectedService.MultiplyBy(5)); }
public void AutofacServiceIsInjected() { var builder = new ContainerBuilder(); builder.RegisterType <Service>().As <IService>() .WithParameter("injectedValue", 5); ConfigurableInjection.InitializeContainer(builder.Build()); var entity = new Entity(5); Assert.IsNotNull(entity.Service); Assert.IsInstanceOf(typeof(Service), entity.Service); Assert.AreEqual(25, entity.Service.MultiplyBy(5)); }
public void SpringServiceIsInjected() { IKernel kernel = new StandardKernel(); kernel.Components.Add <IInjectionHeuristic, PropertyInjectionHeuristic>(); kernel.Bind <IService>().To <Service>().WithConstructorArgument("injectedValue", 5); ConfigurableInjection.InitializeContainer(kernel); var entity = new Entity(5); Assert.IsNotNull(entity.InjectedService); Assert.IsInstanceOf(typeof(Service), entity.InjectedService); // refer to springObjects.xml to see Service and Entity classes configuration Assert.AreEqual(25, entity.InjectedService.MultiplyBy(5)); }
public static void Configure(Assembly assembly) { var builder = new ContainerBuilder(); builder.RegisterType(assembly.GetType("AssemblyToProcess.Service")).As(assembly.GetType("AssemblyToProcess.IService")); builder.RegisterType(assembly.GetType("AssemblyToProcess.Service2")).As(assembly.GetType("AssemblyToProcess.IService2")); builder.RegisterType(assembly.GetType("AssemblyToProcess.ClassWithNoCtors")).AsSelf(); builder.RegisterType(assembly.GetType("AssemblyToProcess.ClassWithStaticCtor")).AsSelf(); builder.RegisterType(assembly.GetType("AssemblyToProcess.ClassWithNoDefaultCtor")).AsSelf(); builder.RegisterType(assembly.GetType("AssemblyToProcess.ClassUsingInjectedPropertyInsideCtor")).AsSelf(); builder.RegisterType(assembly.GetType("AssemblyToProcess.ClassWithManyCtors")).AsSelf(); builder.RegisterType(assembly.GetType("AssemblyToProcess.ClassNotConfigurableInheritingFromBase")).AsSelf(); builder.RegisterType(assembly.GetType("AssemblyToProcess.ClassConfigurableInheritingFromBase")).AsSelf(); ConfigurableInjection.InitializeContainer(builder.Build()); }
public static void Configure(Assembly assembly) { IKernel kernel = new StandardKernel(); kernel.Components.Add <IInjectionHeuristic, PropertyInjectionHeuristic>(); kernel.Bind(assembly.GetType("AssemblyToProcess.IService")).To(assembly.GetType("AssemblyToProcess.Service")); kernel.Bind(assembly.GetType("AssemblyToProcess.IService2")).To(assembly.GetType("AssemblyToProcess.Service2")); kernel.Bind(assembly.GetType("AssemblyToProcess.ClassWithNoCtors")).ToSelf().InTransientScope(); kernel.Bind(assembly.GetType("AssemblyToProcess.ClassWithStaticCtor")).ToSelf().InTransientScope(); kernel.Bind(assembly.GetType("AssemblyToProcess.ClassWithNoDefaultCtor")).ToSelf().InTransientScope(); kernel.Bind(assembly.GetType("AssemblyToProcess.ClassUsingInjectedPropertyInsideCtor")).ToSelf().InTransientScope(); kernel.Bind(assembly.GetType("AssemblyToProcess.ClassWithManyCtors")).ToSelf().InTransientScope(); kernel.Bind(assembly.GetType("AssemblyToProcess.ClassNotConfigurableInheritingFromBase")).ToSelf().InTransientScope(); kernel.Bind(assembly.GetType("AssemblyToProcess.ClassConfigurableInheritingFromBase")).ToSelf().InTransientScope(); ConfigurableInjection.InitializeContainer(kernel); }
public void Setup() { ConfigurableInjection.InitializeContainer(ContextRegistry.GetContext()); }
public static string Run(string[] args) { string error = null; var process = Process.GetProcessesByName(Path.GetFileNameWithoutExtension(Assembly.GetEntryAssembly().Location)); if (process.Length > 1) { error = "An instance of ul-nuget-converter is already running..."; return(error); } //Un comment this line if you want to force logging of Api change analyze //System.Environment.SetEnvironmentVariable("_Trace", "Console; ApiChange.* all"); var options = new CommandLineOptions(); if (!CommandLine.Parser.Default.ParseArguments(args, options)) { error = $"Error while parsing options: {args.Aggregate("",(current, next) => current + "|" + next)}"; return(error); } //When filename is set let's recompute everything if (!string.IsNullOrEmpty(options.Filename)) { options.NoCache = true; } if (string.IsNullOrEmpty(options.OfficialRepository)) { options.OfficialRepository = "https://www.nuget.org/api/v2/"; } ResolutionLevelEnum resolutionLevel = (ResolutionLevelEnum)options.ResolutionLevel; if (options.Proxy != null && options.ProxyWhilelist != null) { WebRequest.DefaultWebProxy = new WebProxy(new Uri(options.Proxy), true, options.ProxyWhilelist.Replace('"', ' ').Trim().Split(',')); } else if (options.Proxy != null) { WebRequest.DefaultWebProxy = new WebProxy(new Uri(options.Proxy), true); } Builder = new ContainerBuilder(); string[] dlls = null; if (string.IsNullOrEmpty(options.Source)) { return(options.GetUsage()); } Trace.TraceInformation("searching for dlls in {0}", options.Source); dlls = Directory.GetFiles(options.Source, "*.dll", SearchOption.AllDirectories); Trace.TraceInformation("{0} dlls found in {1}", dlls.Length, options.Source); if (!Directory.Exists(@"cache")) { Directory.CreateDirectory(@"cache"); } Builder.RegisterType <ConfigurationService>() .WithParameter("path", options.Source) .AsSelf() .SingleInstance(); Builder.RegisterType <VersionResolverService>() .WithParameter(new ResolvedParameter( (pi, c) => pi.ParameterType == (typeof(ConfigurationService)), (pi, c) => c.Resolve(typeof(ConfigurationService)))) .WithParameter("resolutionLevel", resolutionLevel) .AsSelf() .SingleInstance(); Builder.RegisterType <AssemblyCacheService>() .WithParameter("dlls", dlls) .WithParameter(new ResolvedParameter( (pi, c) => pi.ParameterType == (typeof(ConfigurationService)), (pi, c) => c.Resolve(typeof(ConfigurationService)))) .WithParameter(new ResolvedParameter( (pi, c) => pi.ParameterType == (typeof(VersionResolverService)), (pi, c) => c.Resolve(typeof(VersionResolverService)))) .WithParameter("useCache", !options.NoCache) .AsSelf() .SingleInstance(); Builder.RegisterType <MappingService>().AsSelf().SingleInstance() .WithParameter("rootPath", options.Source) .WithParameter("officialRepository", options.OfficialRepository); Builder.RegisterType <DependenciesResolverService>() .WithParameter(new ResolvedParameter( (pi, c) => pi.ParameterType == (typeof(AssemblyCacheService)), (pi, c) => c.Resolve(typeof(AssemblyCacheService)))) .WithParameter(new ResolvedParameter( (pi, c) => pi.ParameterType == (typeof(MappingService)), (pi, c) => c.Resolve(typeof(MappingService)))) .WithParameter("useCache", !options.NoCache) .WithParameter("resolutionLevel", resolutionLevel) .AsSelf().SingleInstance(); Builder.RegisterType <NuGetPackageCreationService>() .WithParameter(new ResolvedParameter( (pi, c) => pi.ParameterType == (typeof(AssemblyCacheService)), (pi, c) => c.Resolve(typeof(AssemblyCacheService)))) .WithParameter(new ResolvedParameter( (pi, c) => pi.ParameterType == (typeof(MappingService)), (pi, c) => c.Resolve(typeof(MappingService)))) .WithParameter(new ResolvedParameter( (pi, c) => pi.ParameterType == (typeof(ConfigurationService)), (pi, c) => c.Resolve(typeof(ConfigurationService)))) .WithParameter(new ResolvedParameter( (pi, c) => pi.ParameterType == (typeof(DependenciesResolverService)), (pi, c) => c.Resolve(typeof(DependenciesResolverService)))) .WithParameter("useCache", !options.NoCache) .WithParameter("repository", options.Repository) .WithParameter("credential", options.RepositoryCredential) .WithParameter("owner", options.Owner) .WithParameter("author", options.Authors) .WithParameter("slackUrl", options.SlackUrl) .WithParameter("slackChannel", options.SlackChannel) .WithParameter("slackUsername", options.SlackUsername) .AsSelf() .SingleInstance(); Container = Builder.Build(); ConfigurableInjection.InitializeContainer(Container); using (var scope = Container.BeginLifetimeScope()) { var packageCreationService = scope.Resolve <NuGetPackageCreationService>(); Trace.TraceInformation("ul-nuget-converter successfully started."); if (options.StartDeamon) { StartDeamon(scope, options); } else if (!string.IsNullOrEmpty(options.Filename)) { CreatePackage(scope, options); } else { packageCreationService.SyncAssembliesPackages(); } } return(null); }