public void Ninject_Supports_Resolving_All_Aspects_From_Container() { var container = new NinjectAspectContainer(); SnapConfiguration.For(container).Configure(c => { c.IncludeNamespace("SnapTests.*"); c.Bind <FirstInterceptor>().To <FirstAttribute>(); c.Bind <SecondInterceptor>().To <SecondAttribute>(); c.AllAspects().KeepInContainer(); }); container.Kernel.Bind <IOrderedCode>().To <OrderedCode>(); container.Kernel.Bind <FirstInterceptor>().ToConstant(new FirstInterceptor("first_kept_in_container")); container.Kernel.Bind <SecondInterceptor>().ToConstant(new SecondInterceptor("second_kept_in_container")); var orderedCode = container.Kernel.Get <IOrderedCode>(); orderedCode.RunInOrder(); // both interceptors are resolved from container CollectionAssert.AreEquivalent( OrderedCode.Actions, new[] { "first_kept_in_container", "second_kept_in_container" }); }
public void When_resolving_services_from_container_SNAP_should_load_dynamicproxygenassebmly2_in_appdomain_only_once() { var container = new ServiceContainer(); SnapConfiguration.For(new LinFuAspectContainer(container)).Configure(c => { c.IncludeNamespaceOf <IBadCode>(); c.Bind <SecondInterceptor>().To <SecondAttribute>(); c.Bind <FirstInterceptor>().To <FirstAttribute>(); c.Bind <HandleErrorInterceptor>().To <HandleErrorAttribute>(); }); container.AddService(typeof(IBadCode), typeof(BadCode)); container.AddService(typeof(IOrderedCode), typeof(OrderedCode)); var orderedCode = container.GetService <IOrderedCode>(); var badCode = container.GetService <IBadCode>(); orderedCode.RunInOrder(); Assert.AreEqual("First", OrderedCode.Actions[1]); Assert.AreEqual("Second", OrderedCode.Actions[0]); Assert.DoesNotThrow(badCode.GiddyUp); var dynamicProxyGenerationAssemblies = AppDomain.CurrentDomain .GetAssemblies() .Where(assembly => assembly.GetName().Name == "DynamicProxyGenAssembly2") .ToList(); Assert.That(dynamicProxyGenerationAssemblies.Count, Is.EqualTo(2)); // both signed and unsigned. Assert.IsNotNull(dynamicProxyGenerationAssemblies.FirstOrDefault(a => a.GetName().GetPublicKey().Length > 0)); Assert.IsNotNull(dynamicProxyGenerationAssemblies.FirstOrDefault(a => a.GetName().GetPublicKey().Length == 0)); }
public void LinFu_Supports_Resolving_Only_Selected_Aspects_From_Container() { var container = new ServiceContainer(); SnapConfiguration.For(new LinFuAspectContainer(container)).Configure(c => { c.IncludeNamespace("SnapTests.*"); c.Bind <FirstInterceptor>().To <FirstAttribute>(); c.Bind <SecondInterceptor>().To <SecondAttribute>(); c.Aspects(typeof(FirstInterceptor)).KeepInContainer(); }); container.AddService(typeof(IOrderedCode), typeof(OrderedCode)); container.AddService(typeof(FirstInterceptor), new FirstInterceptor("first_kept_in_container")); container.AddService(typeof(SecondInterceptor), new SecondInterceptor("second_kept_in_container")); var orderedCode = container.GetService <IOrderedCode>(); orderedCode.RunInOrder(); // first interceptor is resolved from container, while second one is via new() CollectionAssert.AreEquivalent( OrderedCode.Actions, new[] { "first_kept_in_container", "Second" }); }
public void Autofac_Supports_Resolving_Only_Selected_Aspects_From_Container() { var builder = new ContainerBuilder(); SnapConfiguration.For(new AutofacAspectContainer(builder)).Configure(c => { c.IncludeNamespace("SnapTests.*"); c.Bind <FirstInterceptor>().To <FirstAttribute>(); c.Bind <SecondInterceptor>().To <SecondAttribute>(); c.Aspects(typeof(FirstInterceptor)).KeepInContainer(); }); builder.Register(r => new OrderedCode()).As <IOrderedCode>(); builder.Register(r => new FirstInterceptor("first_kept_in_container")); builder.Register(r => new SecondInterceptor("second_kept_in_container")); using (var container = builder.Build()) { var orderedCode = container.Resolve <IOrderedCode>(); orderedCode.RunInOrder(); // first interceptor is resolved from container, while second one is via new() CollectionAssert.AreEquivalent( OrderedCode.Actions, new[] { "first_kept_in_container", "Second" }); } }
public void When_resolving_services_from_container_SNAP_should_load_dynamicproxygenassebmly2_in_appdomain_only_once() { SnapConfiguration.For <StructureMapAspectContainer>(c => { c.IncludeNamespaceOf <IBadCode>(); c.Bind <SecondInterceptor>().To <SecondAttribute>(); c.Bind <FirstInterceptor>().To <FirstAttribute>(); c.Bind <HandleErrorInterceptor>().To <HandleErrorAttribute>(); }); ObjectFactory.Configure(c => c.For <IOrderedCode>().Use <OrderedCode>()); ObjectFactory.Configure(c => c.For <IBadCode>().Use <BadCode>()); var orderedCode = ObjectFactory.GetInstance <IOrderedCode>(); var badCode = ObjectFactory.GetInstance <IBadCode>(); orderedCode.RunInOrder(); Assert.AreEqual("First", OrderedCode.Actions[1]); Assert.AreEqual("Second", OrderedCode.Actions[0]); Assert.DoesNotThrow(badCode.GiddyUp); var dynamicProxyGenerationAssemblies = AppDomain.CurrentDomain .GetAssemblies() .Where(assembly => assembly.GetName().Name == "DynamicProxyGenAssembly2") .ToList(); Assert.That(dynamicProxyGenerationAssemblies.Count, Is.EqualTo(2)); Assert.IsNotNull(dynamicProxyGenerationAssemblies.FirstOrDefault(a => a.GetName().GetPublicKey().Length > 0)); Assert.IsNotNull(dynamicProxyGenerationAssemblies.FirstOrDefault(a => a.GetName().GetPublicKey().Length == 0)); }
public void CastleWindsor_Supports_Resolving_Only_Selected_Aspects_From_Container() { var container = new WindsorContainer(); SnapConfiguration.For(new CastleAspectContainer(container.Kernel)).Configure(c => { c.IncludeNamespace("SnapTests.*"); c.Bind <FirstInterceptor>().To <FirstAttribute>(); c.Bind <SecondInterceptor>().To <SecondAttribute>(); c.Aspects(typeof(FirstInterceptor)).KeepInContainer(); }); container.Register(Component.For(typeof(IOrderedCode)).ImplementedBy(typeof(OrderedCode))); container.Register(Component.For <FirstInterceptor>().Instance(new FirstInterceptor("first_kept_in_container"))); container.Register(Component.For <SecondInterceptor>().Instance(new SecondInterceptor("second_kept_in_container"))); var orderedCode = container.Resolve <IOrderedCode>(); orderedCode.RunInOrder(); // first interceptor is resolved from container, while second one is via new() CollectionAssert.AreEquivalent( OrderedCode.Actions, new[] { "first_kept_in_container", "Second" }); }
public void Ninject_Supports_Types_Without_Interfaces() { var container = new NinjectAspectContainer(); SnapConfiguration.For(container).Configure(c => { c.IncludeNamespace("SnapTests.Fakes*"); c.Bind <HandleErrorInterceptor>().To <HandleErrorAttribute> (); }); container.Kernel.Bind <IDependency>().To <DummyDependency>(); container.Kernel.Bind <TypeWithoutInterface>().To <TypeWithoutInterface>(); var typeWithoutInterface = container.Kernel.Get <TypeWithoutInterface>(); Assert.DoesNotThrow(typeWithoutInterface.Foo); Assert.IsTrue(typeWithoutInterface.GetType().Name.Equals("TypeWithoutInterfaceProxy")); container.Kernel.Bind <TypeWithInterfaceInBaseClass>().To <TypeWithInterfaceInBaseClass>(); var typeWithInterfaceInBaseClass = container.Kernel.Get <TypeWithInterfaceInBaseClass>(); Assert.DoesNotThrow(typeWithInterfaceInBaseClass.Foo); Assert.IsTrue(typeWithInterfaceInBaseClass.GetType().Name.Equals("TypeWithInterfaceInBaseClassProxy")); }
public void Autofac_Supports_Types_Without_Interfaces() { var builder = new ContainerBuilder(); SnapConfiguration.For(new AutofacAspectContainer(builder)).Configure(c => { c.IncludeNamespace("SnapTests.Fakes*"); c.Bind <HandleErrorInterceptor>().To <HandleErrorAttribute>(); }); builder.Register(r => new DummyDependency()).As <IDependency>(); builder.RegisterType(typeof(TypeWithoutInterface)); builder.RegisterType(typeof(TypeWithInterfaceInBaseClass)); using (var container = builder.Build()) { var typeWithoutInterface = container.Resolve <TypeWithoutInterface>(); Assert.DoesNotThrow(typeWithoutInterface.Foo); Assert.IsTrue(typeWithoutInterface.GetType().Name.Equals("TypeWithoutInterfaceProxy")); var typeWithInterfaceInBaseClass = container.Resolve <TypeWithInterfaceInBaseClass>(); Assert.DoesNotThrow(typeWithInterfaceInBaseClass.Foo); Assert.IsTrue(typeWithInterfaceInBaseClass.GetType().Name.Equals("TypeWithInterfaceInBaseClassProxy")); } }
public static void Config(string includeNamespace) { SnapConfiguration.For<StructureMapAspectContainer>(c => { c.IncludeNamespace(includeNamespace); c.Bind<CachingInterceptor>().To<CachingAttribute>(); }); }
static SampleStructureMapAopConfig() { SnapConfiguration.For <StructureMapAspectContainer>(c => { c.IncludeNamespace("ConsoleApplication1*"); c.Bind <SampleInterceptor>().To <SampleAttribute>(); }); ObjectFactory.Configure(c => c.For <ISampleClass>().Use <SampleClass>()); }
public void Namespace_Inclusion_Checks_For_Wildcards() { var container = new MockAspectContainer(); SnapConfiguration.For(container).Configure(c => c.IncludeNamespace("SnapTests*")); var config = container.AspectConfiguration; Assert.IsTrue(config.Namespaces[0].Equals("SnapTests*")); }
public void Structuremap_Container_Succeeds_Without_Match() { SnapConfiguration.For <StructureMapAspectContainer>(c => { c.IncludeNamespace("Does.Not.Work"); c.Bind <HandleErrorInterceptor>().To <HandleErrorAttribute>(); }); ObjectFactory.Configure(c => c.For <IBadCode>().Use <BadCode>()); Assert.DoesNotThrow(() => ObjectFactory.GetInstance <IBadCode>()); }
internal static void RegisterSnap(string nameSpace) { if (!nameSpace.IsNullOrEmpty() && ConfigReservedKeys.SNAP_CACHE.ConfigValue().ToBoolean()) { SnapConfiguration.For <StructureMapAspectContainer>(c => { c.IncludeNamespace(nameSpace); c.Bind <ServiceCacheInterceptor>().To <ServiceCacheAttribute>(); }); } }
public void Structuremap_Container_Allow_Strict_Matching() { SnapConfiguration.For <StructureMapAspectContainer>(c => { c.IncludeNamespace("SnapTests*"); c.Bind <HandleErrorInterceptor>().To <HandleErrorAttribute>(); }); ObjectFactory.Configure(c => c.For <IBadCode>().Use <BadCode>()); Assert.DoesNotThrow(() => ObjectFactory.GetInstance <IBadCode>()); }
static SampleAutofacAopConfig() { _builder = new ContainerBuilder(); SnapConfiguration.For(new AutofacAspectContainer(_builder)).Configure(c => { c.IncludeNamespace("ConsoleApplication1"); c.Bind <SampleInterceptor>().To <SampleAttribute>(); }); _builder.Register(r => new SampleClass()).As <ISampleClass>(); }
public void Structuremap_Container_Ignores_Types_Without_Decoration() { SnapConfiguration.For <StructureMapAspectContainer>(c => { c.IncludeNamespace("Snap.Tests*"); c.Bind <FirstInterceptor>().To <FirstAttribute>(); }); ObjectFactory.Configure(c => c.For <INotInterceptable>().Use <NotInterceptable>()); var code = ObjectFactory.GetInstance <INotInterceptable>(); Assert.IsFalse(code.GetType().Name.Equals("INotInterceptableProxy")); }
public void Namespace_Inclusion_Adds_Wildcards() { var container = new NinjectAspectContainer(); SnapConfiguration.For(container).Configure(c => { c.IncludeNamespace("SnapTests"); c.Bind <HandleErrorInterceptor>().To <HandleErrorAttribute>(); }); container.Kernel.Bind <IBadCode>().To <BadCode>(); Assert.DoesNotThrow(() => container.Kernel.Get <IBadCode>()); }
public void Type_Inclusion_Adds_Type_By_Generic() { var container = new NinjectAspectContainer(); SnapConfiguration.For(container).Configure(c => { c.IncludeType <IBadCode>(); c.Bind <HandleErrorInterceptor>().To <HandleErrorAttribute>(); }); container.Kernel.Bind <IBadCode>().To <BadCode>(); Assert.DoesNotThrow(() => container.Kernel.Get <IBadCode>()); }
public void Class_Interceptors_Does_Not_Run_With_Multicast() { SnapConfiguration.For <StructureMapAspectContainer>(c => { c.IncludeNamespace("SnapTests.Fakes*"); c.Bind <HandleErrorInterceptor>().To <PublicClassAttribute>(); }); ObjectFactory.Configure(c => c.For <BaseAbstractClass>().Use <TypeWithAbstractClass>()); var code = ObjectFactory.GetInstance <BaseAbstractClass>(); Assert.Throws <Exception>(code.CallFoo2); }
public void Snap_Scans_Assemblies_For_Default_Conventions() { SnapConfiguration.For <StructureMapAspectContainer>(c => { c.IncludeNamespace("SnapTest*"); c.Scan(s => s.ThisAssembly().WithDefaults()); }); ObjectFactory.Configure(c => c.For <IBadCode>().Use <BadCode>()); var code = ObjectFactory.GetInstance <IBadCode>(); Assert.DoesNotThrow(code.GiddyUp); }
public void LinFu_Should_Fail_To_Resolve_Component_Which_Is_Not_Registered_With_ServiceNotFoundException() { var container = new ServiceContainer(); SnapConfiguration.For(new LinFuAspectContainer(container)).Configure(c => { c.IncludeNamespace("SnapTests.*"); c.Bind <FirstInterceptor>().To <FirstAttribute>(); c.Bind <SecondInterceptor>().To <SecondAttribute>(); }); Assert.Throws <ServiceNotFoundException>(() => container.GetService <IOrderedCode>()); }
public void StructureMap_Container_Supports_Method_Aspects() { SnapConfiguration.For <StructureMapAspectContainer>(c => { c.IncludeNamespace("SnapTests.Fakes*"); c.Bind <HandleErrorInterceptor>().To <HandleErrorAttribute>(); }); ObjectFactory.Configure(c => c.For <IBadCode>().Use <BadCode>()); var badCode = ObjectFactory.GetInstance <IBadCode>(); Assert.DoesNotThrow(badCode.GiddyUp); Assert.IsTrue(badCode.GetType().Name.Equals("IBadCodeProxy")); }
public void LinFu_Container_Allow_Strict_Matching() { var container = new ServiceContainer(); container.LoadFrom(AppDomain.CurrentDomain.BaseDirectory, "*.dll"); SnapConfiguration.For(new LinFuAspectContainer(container)).Configure(c => { c.IncludeNamespace("SnapTests.*"); c.Bind <HandleErrorInterceptor>().To <HandleErrorAttribute>(); }); Assert.DoesNotThrow(() => container.GetService <IBadCode>()); }
public void SimpleInjector_Container_Fails_Without_Match() { var container = new SimpleInjectorAspectContainer(new Container()); SnapConfiguration.For(container).Configure(c => { c.IncludeNamespace("Does.Not.Work"); c.Bind <HandleErrorInterceptor>().To <HandleErrorAttribute> (); }); container.Container.Register <IBadCode, BadCode>(); Assert.Throws <ActivationException>(() => container.Container.GetInstance <IBadCode>()); }
public void LinFu_Container_Fails_Without_Match() { var container = new ServiceContainer(); container.LoadFrom(AppDomain.CurrentDomain.BaseDirectory, "*.dll"); SnapConfiguration.For(new LinFuAspectContainer(container)).Configure(c => { c.IncludeNamespace("Does.Not.Work"); c.Bind <HandleErrorInterceptor>().To <HandleErrorAttribute>(); }); Assert.Throws <NullReferenceException>(() => container.GetService <IBadCode>()); }
public void Ninject_Container_Allow_Strict_Matching() { var container = new NinjectAspectContainer(); SnapConfiguration.For(container).Configure(c => { c.IncludeNamespace("SnapTests.Fakes.IBadCode"); c.Bind <HandleErrorInterceptor>().To <HandleErrorAttribute> (); }); container.Kernel.Bind <IBadCode>().To <BadCode>(); Assert.DoesNotThrow(() => container.Kernel.Get <IBadCode>()); }
public void SimpleInjector_Container_Allow_Strict_Matching() { var container = new SimpleInjectorAspectContainer(new Container()); SnapConfiguration.For(container).Configure(c => { c.IncludeNamespace("SnapTests.Fakes.IBadCode"); c.Bind <HandleErrorInterceptor>().To <HandleErrorAttribute> (); }); container.Container.Register <IBadCode, BadCode>(); Assert.DoesNotThrow(() => container.Container.GetInstance <IBadCode>()); }
public void Namespace_Inclusion_Adds_Namespace_and_Nested_Namespaces_Of_A_Given_Type() { var container = new NinjectAspectContainer(); SnapConfiguration.For(container).Configure(c => { // AspectConfiguration have the same namespace prefix as IBadCode's namespace c.IncludeNamespaceOf <AspectConfiguration>(true); c.Bind <HandleErrorInterceptor>().To <HandleErrorAttribute>(); }); container.Kernel.Bind <IBadCode>().To <BadCode>(); Assert.DoesNotThrow(() => container.Kernel.Get <IBadCode>()); }
public void Ninject_Container_Fails_Without_Match() { var container = new NinjectAspectContainer(); SnapConfiguration.For(container).Configure(c => { c.IncludeNamespace("Does.Not.Work"); c.Bind <HandleErrorInterceptor>().To <HandleErrorAttribute> (); }); container.Kernel.Bind <IBadCode>().To <BadCode>(); Assert.Throws <NullReferenceException>(() => container.Kernel.Get <IBadCode>()); }
public void Snap_Allows_Custom_Scanning_Conventions() { var scanner = new CustomPrefixScanner(); SnapConfiguration.For <StructureMapAspectContainer>(c => { c.IncludeNamespace("SnapTest*"); c.Scan(s => s.ThisAssembly().With(scanner)); }); ObjectFactory.Configure(c => c.For <IBadCode>().Use <BadCode>()); var code = ObjectFactory.GetInstance <IBadCode>(); Assert.DoesNotThrow(code.GiddyUp); }