public void SimpleDependencyTest()
        {
            var actual   = container.Resolve <ISimpleDependency>();
            var expected = new SimpleDependency();

            Assert.AreEqual(expected, actual);
        }
 public ComplexDependency(SimpleDependency dependency)
 {
     if (dependency == null)
     {
         throw new ArgumentException();
     }
     Dependency = dependency;
 }
 public OperationWithDependencies(SimpleDependency dependency)
 {
     if (dependency == null)
     {
         throw new ArgumentException();
     }
     Dependency = dependency;
 }
Ejemplo n.º 4
0
        public void Should_convert_interface_with_autofac_having_non_default_ctor()
        {
            var simpleDep = new SimpleDependency();

            _typesToConvertViaAutofac.Add(new AutofacJsonTokenConverterType(typeof(IConfigurationWithNonDefaultCtor)));
            _builder.RegisterType <ConfigurationWithNonDefaultCtor>().AsImplementedInterfaces();
            _builder.RegisterInstance(simpleDep);
            var tokens = GetTokens(new {});

            var config = Create().Convert <IConfigurationWithNonDefaultCtor>(tokens);

            config.Should().NotBeNull();
            config.SimpleDependency.Should().Be(simpleDep);
        }
Ejemplo n.º 5
0
        public void TestLifetimeManagerRegisterResolve()
        {
            var dependency = new SimpleDependency();

            var lifetimeManager = new SingletonLifetimeManager(dependency);

            bool keepTrackObject;
            var  resolvedObject1 = lifetimeManager.Resolve(null, out keepTrackObject);

            Assert.IsNotNull(resolvedObject1);

            var resolvedObject2 = lifetimeManager.Resolve(null, out keepTrackObject);

            Assert.IsNotNull(resolvedObject2);

            Assert.AreSame(resolvedObject1, resolvedObject2);
            Assert.AreEqual(SimpleDependency.ActiveDependecies, 1);

            dependency.Dispose();
        }
        private void Start()
        {
            var simpleDep = new SimpleDependency();

            var context = Context.Create()
                          .RegisterDependency(simpleDep)
                          .RegisterType <AutocomposedDependency>()
                          .RegisterType <DependencyInherited>()
                          .RegisterDependencyAs <IDependencyImpl, IDependency>(new IDependencyImpl())
                          .RegisterTypeAs <IDependencyAutoImpl, IDependencyAuto>();

            Assert.NotNull(context.TestResolve <SimpleDependency>(), "resolve simple");
            AutocomposedDependency auto = context.TestResolve <AutocomposedDependency>();

            Assert.NotNull(auto, "resolve auto");
            Assert.NotNull(auto.ConstructorInjected, "auto constructor injected");
            Assert.NotNull(auto.PropertyInjected, "auto property injected");
            Assert.NotNull(auto.FieldInjected, "auto field injected");
            Assert.NotNull(auto.Created, "local creation");
            Assert.NotNull(auto.Created._dependency, "local creation dep not null");
            Assert.Equals(simpleDep, auto.FieldInjected, "auto field injected equals");
            Assert.NotNull(auto.InitInjected, "auto Init injected");

            DependencyInherited inherit = context.TestResolve <DependencyInherited>();

            Assert.NotNull(inherit, "resolve child");
            Assert.NotNull(inherit.AdditionalChildDep, "child own dep");
            Assert.NotNull(inherit.PropertyInjected, "child inherited property dep");
            Assert.NotNull(inherit.FieldInjected, "child inherited field dep");
            Assert.NotNull(inherit.InitInjected, "child inherited method dep");
            Assert.Equals(inherit.InjCount, 1, "child injection called only once");

            Assert.NotNull(context.TestResolve <IDependency>(), "resolve interface");
            Assert.NotNull(context.TestResolve <IDependencyAuto>(), "resolve auto interface");

            context.Destroy();
        }
 public AutocomposedDependency(SimpleDependency foo)
 {
     ConstructorInjected = foo;
 }
 public DependencyInherited(SimpleDependency dep) : base(dep)
 {
 }
 public OperationWithTwoConstructors(SimpleDependency dependency) { }
Ejemplo n.º 10
0
 public ConfigurationWithNonDefaultCtor(SimpleDependency simpleDependency)
 {
     SimpleDependency = simpleDependency;
 }
 public OperationWithDependencies(SimpleDependency dependency)
 {
     if (dependency == null) throw new ArgumentException();
     Dependency = dependency;
 }
Ejemplo n.º 12
0
 public void TestInitialize()
 {
     SimpleDependency.ResetCounters();
 }
        public void Dependencies_registered_as_instances_are_preferred_over_instances_registered_as_types(WorkflowConfiguration configuration, SimpleDependency instance)
        {
            var sut = new SimpleOperationResolver();

            sut.RegisterOperationDependency <SimpleDependency, SimpleDependency>();
            sut.RegisterOperationDependencyInstance(instance);

            var result = (OperationWithDependencies)sut.Resolve <OperationWithDependencies>(configuration);

            Assert.Equal(instance, result.Dependency);
        }
 public OperationWithTwoConstructors(SimpleDependency dependency)
 {
 }
 public DependencyWithTwoConstructors(SimpleDependency dependency)
 {
 }
 public void Init(SimpleDependency foo)
 {
     InitInjected = foo;
 }
 public virtual void CheckTwice(SimpleDependency foo)
 {
     InjCount++;
 }
 public ComplexDependency(SimpleDependency dependency)
 {
     if (dependency == null) throw new ArgumentException();
     Dependency = dependency;
 }
Ejemplo n.º 19
0
 public SimpleService(SimpleDependency dependency)
 {
     Dependency = dependency;
 }
 public DependencyWithTwoConstructors(SimpleDependency dependency) { }