public void RegistersTests_ComposeAssembly_CompositionRootNotFound() { IStashboxContainer container = new StashboxContainer(); Assert.Throws <CompositionRootNotFoundException>(() => container.ComposeAssemblies(new[] { typeof(IStashboxContainer).GetTypeInfo().Assembly })); }
private static void Main(string[] args) { var container = new StashboxContainer(configurator => { configurator.WithDisposableTransientTracking(); }); // Scan assemblies by ICompositionRoot container.ComposeAssemblies(new List <Assembly> { Assembly.GetExecutingAssembly() }); var rc = HostFactory.Run(x => { x.Service <IQuartzScheduleJobManager>(s => { s.ConstructUsing(name => container.Resolve <IQuartzScheduleJobManager>()); s.WhenStarted(tc => tc.Start()); s.WhenStopped(tc => tc.Stop()); }); x.RunAsLocalSystem(); x.SetDescription("Sample Topshelf Host"); x.SetDisplayName("Stuff"); x.SetServiceName("Stuff"); }); var exitCode = (int)Convert.ChangeType(rc, rc.GetTypeCode()); Environment.ExitCode = exitCode; }
public void RegistersTests_ComposeAssemblies() { IStashboxContainer container = new StashboxContainer(); container.ComposeAssemblies(new[] { this.GetType().GetTypeInfo().Assembly }); var regs = container.ContainerContext.RegistrationRepository.GetAllRegistrations().OrderBy(r => r.RegistrationNumber).ToArray(); Assert.AreEqual(4, regs.Length); Assert.AreSame(regs[0].ImplementationType, typeof(Test)); Assert.AreSame(regs[1].ImplementationType, typeof(Test1)); Assert.AreSame(regs[2].ImplementationType, typeof(Test11)); Assert.AreSame(regs[3].ImplementationType, typeof(Test12)); }
public void RegistersTests_ComposeAssemblies() { IStashboxContainer container = new StashboxContainer(); container.ComposeAssemblies(new[] { this.GetType().GetTypeInfo().Assembly }, type => !type.FullName.Contains("IssueTests")); var regs = container.ContainerContext.RegistrationRepository .GetRegistrationMappings() .OrderBy(r => r.Value.RegistrationId) .ToArray(); Assert.Equal(4, regs.Length); Assert.Same(regs[0].Value.ImplementationType, typeof(Test)); Assert.Same(regs[1].Value.ImplementationType, typeof(Test1)); Assert.Same(regs[2].Value.ImplementationType, typeof(Test11)); Assert.Same(regs[3].Value.ImplementationType, typeof(Test12)); }
public void ContainerTests_Throws_Disposed_Exceptions() { var container = new StashboxContainer(); container.Dispose(); Assert.Throws <ObjectDisposedException>(() => container.Activate(this.GetType())); Assert.Throws <ObjectDisposedException>(() => container.BeginScope()); Assert.Throws <ObjectDisposedException>(() => container.BuildUp(new object())); Assert.Throws <ObjectDisposedException>(() => container.CanResolve(this.GetType())); Assert.Throws <ObjectDisposedException>(() => container.ComposeAssemblies(new[] { this.GetType().GetTypeInfo().Assembly })); Assert.Throws <ObjectDisposedException>(() => container.ComposeAssembly(this.GetType().GetTypeInfo().Assembly)); Assert.Throws <ObjectDisposedException>(() => container.ComposeBy(this.GetType())); Assert.Throws <ObjectDisposedException>(() => container.Configure(c => { })); Assert.Throws <ObjectDisposedException>(() => container.CreateChildContainer()); Assert.Throws <ObjectDisposedException>(() => container.GetRegistrationMappings()); #if HAS_SERVICEPROVIDER Assert.Throws <ObjectDisposedException>(() => container.GetService(this.GetType())); #endif Assert.Throws <ObjectDisposedException>(() => container.IsRegistered(this.GetType())); Assert.Throws <ObjectDisposedException>(() => container.PutInstanceInScope(this.GetType())); Assert.Throws <ObjectDisposedException>(() => container.Register(this.GetType())); Assert.Throws <ObjectDisposedException>(() => container.RegisterAssemblies(new[] { this.GetType().GetTypeInfo().Assembly })); Assert.Throws <ObjectDisposedException>(() => container.RegisterAssembly(this.GetType().GetTypeInfo().Assembly)); Assert.Throws <ObjectDisposedException>(() => container.RegisterAssemblyContaining <ITest1>()); Assert.Throws <ObjectDisposedException>(() => container.RegisterDecorator(this.GetType(), this.GetType())); Assert.Throws <ObjectDisposedException>(() => container.RegisterFunc <ITest1>(r => new Test1())); Assert.Throws <ObjectDisposedException>(() => container.RegisterInstance(new object())); Assert.Throws <ObjectDisposedException>(() => container.RegisterInstances(new object())); Assert.Throws <ObjectDisposedException>(() => container.RegisterResolver(null)); Assert.Throws <ObjectDisposedException>(() => container.RegisterScoped <ITest1, Test1>()); Assert.Throws <ObjectDisposedException>(() => container.RegisterSingleton <ITest1, Test1>()); Assert.Throws <ObjectDisposedException>(() => container.RegisterTypes(new [] { this.GetType() })); Assert.Throws <ObjectDisposedException>(() => container.RegisterTypesAs <ITest1>(this.GetType().GetTypeInfo().Assembly)); Assert.Throws <ObjectDisposedException>(() => container.ReMap <ITest1, Test1>()); Assert.Throws <ObjectDisposedException>(() => container.ReMapDecorator(this.GetType(), this.GetType())); Assert.Throws <ObjectDisposedException>(() => container.Resolve(this.GetType())); Assert.Throws <ObjectDisposedException>(() => container.ResolveAll(this.GetType())); Assert.Throws <ObjectDisposedException>(() => container.ResolveFactory(this.GetType())); Assert.Throws <ObjectDisposedException>(() => container.Validate()); Assert.Throws <ObjectDisposedException>(() => container.WireUp(new object())); }
public void RegistersTests_ComposeAssembly_CompositionRootNotFound() { IStashboxContainer container = new StashboxContainer(); container.ComposeAssemblies(new[] { typeof(IStashboxContainer).GetTypeInfo().Assembly }); }