Beispiel #1
0
        private IJSEngine GetJSEngine(string serverAddress = "http://127.0.0.1:1234")
        {
            var option = new CreateOption
            {
                Endpoint = serverAddress
            };

            return(IoCContainerBuilder.Build(option).Resolve <IJSEngine>());
        }
Beispiel #2
0
        protected void Application_Start()
        {
            IoCContainerBuilder.BuildDependencyResolver(typeof(MvcApplication).Assembly);

            AreaRegistration.RegisterAllAreas();
            FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
            RouteConfig.RegisterRoutes(RouteTable.Routes);
            BundleConfig.RegisterBundles(BundleTable.Bundles);
        }
 public void Should_AddSetDelegateAndLookupType()
 {
     var builder = new IoCContainerBuilder();
     var component = builder.AddInstance(() => 3).ForSelf();
     Assert.IsNotNull(component.ComponentRegistration.CreateType);
     Assert.IsNotNull(component.ComponentRegistration.LookupTypes.First());
     Assert.IsNotNull(component.ComponentRegistration.ResultFunc);
     Assert.IsTrue(component.ComponentRegistration.CreateType == typeof(int));
     Assert.IsNotNull(component.ComponentRegistration.LookupTypes.First() == typeof(int));
     Assert.IsTrue(component.ComponentRegistration.ResultFunc() is int);
 }
Beispiel #4
0
    public IScopedDependencyResolver GetResolver()
    {
        var builder = new IoCContainerBuilder();

        builder.AddResttpControllers(Assembly.GetExecutingAssembly());

        builder.AddInstance(() => 3).For<int>();

        builder.AddType<Object>().ForSelf().WithParameters(new Parameter("Labas", "labas")).SetSingleton();
        builder.AddType<Object>().For<IList>().SetPerDependency();
        builder.AddType<Object>().ForImplementedInterfaces().SetPerRequest();

        builder.AddInstance(() => new Object()).For<Object>().SetSingleton();
        builder.AddInstance(() => new object()).ForSelf().SetPerRequest();
        builder.AddInstance(() => new object()).ForImplementedInterfaces().SetPerDependency();
        return builder.Build();
    }
 public void Should_UseDefaultParameters()
 {
     var builder = new IoCContainerBuilder();
     builder
         .AddType<AParam>().ForSelf()
         .WithParameters(new Parameter("sk", 5))
         .SetSingleton();
     var container = builder.Build();
     var a = container.Resolve<AParam>();
     Assert.IsNotNull(a);
     Assert.AreEqual(a.Sk, 5);
 }
 public void Should_ReturnNullIfNotRegistered()
 {
     var builder = new IoCContainerBuilder();
     var container = builder.Build();
     try
     {
         var ia1 = container.Resolve<IA1>();
         Assert.Fail();
     }
     catch (Exception) { }
 }
 public void Should_ResolveTwoInterfacesWithSameClass()
 {
     var builder = new IoCContainerBuilder();
     builder.AddType<A>().For<IA1>().SetSingleton();
     builder.AddType<A>().For<IA2>().SetSingleton();
     var container = builder.Build();
     var ia1 = container.Resolve<IA1>();
     var ia2 = container.Resolve<IA2>();
     Assert.IsNotNull(ia1);
     Assert.IsNotNull(ia2);
     Assert.AreNotSame(ia1, ia2);
 }
 public void Should_ResolveNestedDependencies()
 {
     var builder = new IoCContainerBuilder();
     builder.AddType<A>().ForSelf().SetSingleton();
     builder.AddType<ANested>().ForSelf().SetSingleton();
     var container = builder.Build();
     var aNested = container.Resolve<ANested>();
     Assert.IsNotNull(aNested);
 }
 public void Should_ResolveAddType()
 {
     var builder = new IoCContainerBuilder();
     builder.AddType<A>().For<IA1>().SetSingleton();
     var container = builder.Build();
     var ia1 = container.Resolve<IA1>();
     Assert.IsNotNull(ia1);
 }
 public void Should_ResolveAddInstance2()
 {
     var builder = new IoCContainerBuilder();
     builder.AddInstance(() => new A()).ForSelf().SetSingleton();
     var container = builder.Build();
     var a = container.Resolve<A>();
     Assert.IsNotNull(a);
 }
 public void Should_ResolveAddInstance1()
 {
     var builder = new IoCContainerBuilder();
     builder.AddInstance<IA1>(() => new A()).ForSelf().SetSingleton();
     var container = builder.Build();
     var ia1 = container.Resolve<IA1>();
     var ia2 = container.Resolve<IA1>();
     Assert.IsNotNull(ia1);
     Assert.IsNotNull(ia2);
     Assert.AreSame(ia1, ia2);
 }
Beispiel #12
0
 public Command(BaseOption option)
 {
     _baseOption = option;
     _scope      = IoCContainerBuilder.Build(option);
     _engine     = _scope.Resolve <IJSEngine>();
 }