public static void WireUp(UnityDependencyResolver dependencyResolver)
 {
     string groupBrushRedisHostname = CloudConfigurationManager.GetSetting("GroupBrushRedisHostname");
     string groupBrushRedisPassword = CloudConfigurationManager.GetSetting("GroupBrushRedisPassword");
     string strUseRedis = CloudConfigurationManager.GetSetting("UseRedis") ?? "false";
     bool useRedis = bool.Parse(strUseRedis);
     RedisConfiguration redisConfiguration = new RedisConfiguration(groupBrushRedisHostname, groupBrushRedisPassword, useRedis);
     dependencyResolver.RegisterInstance<RedisConfiguration>(redisConfiguration);
     string groupBrushSQLConnectionString = CloudConfigurationManager.GetSetting("GroupBrushDB");
     dependencyResolver.RegisterType<IUserService, UserService>(new ContainerControlledLifetimeManager());
     dependencyResolver.RegisterType<ICanvasService, CanvasService>();
     dependencyResolver.RegisterType<ICanvasRoomService, CanvasRoomService>();
     if (useRedis)
     {
         dependencyResolver.RegisterType<IMemStorage, RedisStorage>(new ContainerControlledLifetimeManager(), new InjectionConstructor(redisConfiguration));
     }
     else
     {
         dependencyResolver.RegisterType<IMemStorage, MemoryStorage>(new ContainerControlledLifetimeManager());
     }
     dependencyResolver.Register(typeof(IGetUserNameFromIdData), () => new GetUserNameFromIdData(groupBrushSQLConnectionString));
     dependencyResolver.Register(typeof(IGetCanvasDescriptionData), () => new GetCanvasDescriptionData(groupBrushSQLConnectionString));
     dependencyResolver.Register(typeof(ICreateUserData), () => new CreateUserData(groupBrushSQLConnectionString));
     dependencyResolver.Register(typeof(IValidateUserData), () => new ValidateUserData(groupBrushSQLConnectionString));
     dependencyResolver.Register(typeof(ICreateCanvasData), () => new CreateCanvasData(groupBrushSQLConnectionString));
     dependencyResolver.Register(typeof(ILookUpCanvasData), () => new LookUpCanvasData(groupBrushSQLConnectionString));
 }
Exemplo n.º 2
0
        public static void Initialise()
        {
            var container = BuildUnityContainer();

            UnityDependencyResolver dr = new UnityDependencyResolver(container);
            GlobalConfiguration.Configuration.DependencyResolver = new ApiContainer();
            DependencyResolver.SetResolver(dr);
        }
            public override void Setup()
            {
                IUnityContainer container = new UnityContainer()
                    .RegisterType<SimpleDependency, SimpleDependency>()
                    .RegisterType<IDependency, SimpleDependency>()
                    .RegisterType<NestedDependency, NestedDependency>();

                _dependencyResolver = new UnityDependencyResolver(container);
            }
Exemplo n.º 4
0
        /// <summary>
        /// Integrates Unity when the application starts.
        /// </summary>
        public static void Start()
        {
            // Use UnityHierarchicalDependencyResolver if you want to use
            // a new child container for each IHttpController resolution.
            // var resolver = new UnityHierarchicalDependencyResolver(UnityConfig.Container);
            var resolver = new UnityDependencyResolver(UnityConfig.Container);

            GlobalConfiguration.Configuration.DependencyResolver = resolver;
        }
Exemplo n.º 5
0
        public virtual void Start()
        {
            var logger = ConfigureSerilog(new LoggerConfiguration()).CreateLogger();
            Log.Logger = logger;

            System = ActorSystem.Create(ActorSystemName);
            Resolver = new UnityDependencyResolver(Container, System);
            CreateActors(System);
        }
Exemplo n.º 6
0
 public void Configuration(IAppBuilder app)
 {
     string strUseRedis = CloudConfigurationManager.GetSetting("UseRedis") ?? "false";
     bool useRedis = bool.Parse(strUseRedis);
     var dependencyResolver = new UnityDependencyResolver();
     UnityWireupConfiguration.WireUp(dependencyResolver);
     GlobalHost.DependencyResolver = dependencyResolver;
     var options = new CookieAuthenticationOptions()
     {
         AuthenticationType = CookieAuthenticationDefaults.AuthenticationType,
         LoginPath = new PathString("/"),
         LogoutPath = new PathString("/")
     };
     app.UseCookieAuthentication(options);
     app.Use(async (context, next) =>
     {
         if (context.Request.Path.Value.Equals("/") ||
         context.Request.Path.Value.StartsWith("/public", StringComparison.CurrentCultureIgnoreCase))
         {
             await next();
         }
         else if (context.Request.User == null || !context.Request.User.Identity.IsAuthenticated)
         {
             context.Response.StatusCode = 401;
         }
         else
         {
             await next();
         }
     });
     HttpConfiguration webApiConfiguration = new HttpConfiguration();
     webApiConfiguration.DependencyResolver = dependencyResolver;
     webApiConfiguration.MapHttpAttributeRoutes();
     app.UseWebApi(webApiConfiguration);
     RedisConfiguration redisConfiguration = dependencyResolver.Resolve<RedisConfiguration>();
     if (redisConfiguration.UseRedis)
     {
         GlobalHost.DependencyResolver.UseRedis(redisConfiguration.HostName, redisConfiguration.Port, redisConfiguration.Password, redisConfiguration.EventKey);
     }
     app.MapSignalR();
     var sharedOptions = new SharedOptions()
     {
         RequestPath = new PathString(string.Empty),
         FileSystem =
             new PhysicalFileSystem(".//public//content")
     };
     app.UseDefaultFiles(new Microsoft.Owin.StaticFiles.DefaultFilesOptions(sharedOptions)
     {
         DefaultFileNames = new List<string>() { "index.html" }
     });
     app.UseStaticFiles("/public");
     app.UseStaticFiles("/content");
     app.UseStaticFiles("/scripts");
     app.UseStaticFiles("/styles");
     app.UseStaticFiles(new StaticFileOptions(sharedOptions));
 }
Exemplo n.º 7
0
        /// <summary>Integrates Unity when the application starts.</summary>
        public static void Start()
        {
            // Use UnityHierarchicalDependencyResolver if you want to use a new child container for each IHttpController resolution.
            // var resolver = new UnityHierarchicalDependencyResolver(UnityConfig.GetConfiguredContainer());
            var resolver = new UnityDependencyResolver(UnityConfig.GetConfiguredContainer());

            GlobalConfiguration.Configuration.DependencyResolver = resolver;

            //Microsoft.Web.Infrastructure.DynamicModuleHelper.DynamicModuleUtility.RegisterModule(typeof(UnityPerRequestHttpModule));
        }
Exemplo n.º 8
0
        public static void InitializeDependencyConfig()
        {
            IUnityContainer         container = BuildUnityContainer();
            UnityDependencyResolver unityDependencyResolver = new UnityDependencyResolver(container);

            DependencyResolver.SetResolver(unityDependencyResolver);

            // Setting application wide services. This enables us to use the services in framework level.
            ApplicationFoundation.SetDependencyResolver(unityDependencyResolver);
        }
 public void When_resolving_unregistered_type_then_returns_null()
 {
     using (var container = new UnityContainer())
     {
         using (var resolver = new UnityDependencyResolver(container))
         {
             Assert.IsNull(resolver.GetService(typeof(IFoo)));
         }
     }
 }
Exemplo n.º 10
0
        public static void Configure()
        {
            IUnityContainer container = new UnityContainer();

            Services.App_Start.UnityConfig.Configure(container);

            UnityDependencyResolver resolver = new UnityDependencyResolver(container);

            GlobalConfiguration.Configuration.DependencyResolver = resolver;
        }
Exemplo n.º 11
0
        /// <summary>
        /// Integrates Unity when the application starts.
        /// </summary>
        public static void Start()
        {
            // Use UnityHierarchicalDependencyResolver if you want to use
            // a new child container for each IHttpController resolution.
            // var resolver = new UnityHierarchicalDependencyResolver(UnityConfig.Container);
            var resolver = new UnityDependencyResolver(UnityConfig.Container);

            GlobalConfiguration.Configuration.DependencyResolver = resolver;
            GlobalHost.DependencyResolver = new SignalRUnityDependencyResolver(UnityConfig.Container);//Ovo dodati u slucaju da je potreban dependency injection
        }
        public void IsRegistered_Should_Return_True()
        {
            var resolver = new UnityDependencyResolver();
            resolver.RegisterType<IFace1, Class1>();
            resolver.RegisterType<IFace1, Class2>();
            resolver.RegisterInstance<IFace1>(new Class3());

            var result = resolver.IsRegistered<IFace1>();
            Assert.IsTrue(result);
        }
Exemplo n.º 13
0
 private static void RegisterActorSystem()
 {
     //Warning:
     //When the hosting inside of IIS the applicationpool the app lives in could be stopped and started at the whim of IIS.
     //This in turn means your ActorSystem could be stopped at any given time.
     //http://getakka.net/docs/deployment-scenarios/ASP%20NET
     ActorSystem = ActorSystem.Create("ticketStore");
     var resolver = new UnityDependencyResolver(UnityConfig.GetConfiguredContainer(), ActorSystem);
     OrderProcessorActor = ActorSystem.ActorOf(ActorSystem.DI().Props<OrderProcessorActor>(), "OrderProcessor");
 }
Exemplo n.º 14
0
        /// <summary>
        /// Integrates Unity when the application starts.
        /// </summary>
        public static void Start()
        {
            // Use UnityHierarchicalDependencyResolver if you want to use
            // a new child container for each IHttpController resolution.
//             var resolver = new UnityHierarchicalDependencyResolver(UnityConfig.Container);
            var resolver = new UnityDependencyResolver(UnityConfig.Container);

            GlobalConfiguration.Configuration.DependencyResolver = resolver;
//            GlobalConfiguration.Configuration.Filters.Add(
//                (SprintActionFilter)resolver.GetService(typeof(SprintActionFilter)));
        }
    private void Application_Start(object sender, EventArgs e)
    {
        IUnityContainer container = new UnityContainer();

        container.RegisterType <IUserService, UserService>();
        container.RegisterType <IUserLogic, UserLogic>();
        UnityDependencyResolver dependencyResolver = new UnityDependencyResolver(container);

        GlobalConfiguration.Configuration.DependencyResolver = dependencyResolver;
        DependencyResolver.SetResolver(dependencyResolver);
    }
Exemplo n.º 16
0
        protected void Application_Start()
        {
            IUnityContainer         unityContainer    = UnityContainerHelper.InitUnityContainer();
            UnityDependencyResolver dependencyRcolver = new UnityDependencyResolver(unityContainer);

            DependencyResolver.SetResolver(dependencyRcolver);
            AreaRegistration.RegisterAllAreas();
            FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
            RouteConfig.RegisterRoutes(RouteTable.Routes);
            BundleConfig.RegisterBundles(BundleTable.Bundles);
        }
Exemplo n.º 17
0
        private static void RegisterActorSystem()
        {
            //Warning:
            //When the hosting inside of IIS the applicationpool the app lives in could be stopped and started at the whim of IIS.
            //This in turn means your ActorSystem could be stopped at any given time.
            //http://getakka.net/docs/deployment-scenarios/ASP%20NET
            ActorSystem = ActorSystem.Create("ticketStore");
            var resolver = new UnityDependencyResolver(UnityConfig.GetConfiguredContainer(), ActorSystem);

            OrderProcessorActor = ActorSystem.ActorOf(ActorSystem.DI().Props <OrderProcessorActor>(), "OrderProcessor");
        }
Exemplo n.º 18
0
        public void Configuration(IAppBuilder app)
        {
            ConfigureAuth(app);

            HttpConfiguration config = new HttpConfiguration();
            var resolver             = new UnityDependencyResolver(UnityConfig.GetConfiguredContainer());

            config.DependencyResolver = resolver;

            app.UseWebApi(config);
        }
Exemplo n.º 19
0
        /// <summary>
        /// Integrates Unity when the application starts.
        /// </summary>
        public static void Start()
        {
            // Use UnityHierarchicalDependencyResolver if you want to use
            // a new child container for each IHttpController resolution.
            // var resolver = new UnityHierarchicalDependencyResolver(UnityConfig.Container);
            var resolver = new UnityDependencyResolver(UnityConfig.Container);

            GlobalConfiguration.Configuration.DependencyResolver = resolver;
            //For mvc controllers
            System.Web.Mvc.DependencyResolver.SetResolver(new Unity.Mvc5.UnityDependencyResolver(UnityConfig.Container));
        }
        /// <summary>Integrates Unity when the application starts.</summary>
        public static void Start()
        {
            // Use UnityHierarchicalDependencyResolver if you want to use a new child container for each IHttpController resolution.
            // var resolver = new UnityHierarchicalDependencyResolver(UnityConfig.GetConfiguredContainer());
            var resolver = new UnityDependencyResolver(UnityConfig.GetConfiguredContainer());

            GlobalConfiguration.Configuration.DependencyResolver = resolver;
            var reflector = UnityConfig.GetConfiguredContainer().Resolve(typeof(IReflector), null) as IReflector;

            reflector.Reflect();
        }
Exemplo n.º 21
0
        protected TestBase()
            : base(
                CreateSpecConfig("FullUri=file:memdb-" + Counter.IncrementAndGet() + ".db?mode=memory&cache=shared;"),
                GetUniqueActorSystemName())
        {
            SqlitePersistence.Get(Sys);

            Container = new UnityContainer();
            Container.RegisterInstance(EventFilter);
            _resolver = new UnityDependencyResolver(Container, Sys);
        }
        public void TestGetServiceFromDependencyResolver()
        {
            //arrange
            IUnityContainer     container          = InitialUnityContainer();
            IDependencyResolver dependencyResolver = new UnityDependencyResolver(container);

            //act
            var controllerActivator = dependencyResolver.GetService <IControllerActivator>();

            //assert
            Assert.NotNull(controllerActivator);
        }
Exemplo n.º 23
0
        public static void Initialise()
        {
            var container = BuildUnityContainer();

            IDependencyResolver resolver = DependencyResolver.Current;

            DependencyResolver.SetResolver(new UnityDependencyResolver(container, resolver));

            IDependencyResolver newResolver = new UnityDependencyResolver(container, resolver);

            DependencyResolver.SetResolver(newResolver);
        }
Exemplo n.º 24
0
        public void Init()
        {
            var resolver = new UnityDependencyResolver(_container);

            // New instance on DI
            _container.RegisterType <IProduct, Product>();


            // Singleton
            _container.RegisterType <IProduct, Product>(new ContainerControlledLifetimeManager());
            _container.RegisterSingleton <IProduct, Product>();
        }
Exemplo n.º 25
0
        protected void Application_Start()
        {
            AreaRegistration.RegisterAllAreas();

            RegisterGlobalFilters(GlobalFilters.Filters);
            RegisterRoutes(RouteTable.Routes);

            var unityDependencyResolver = new UnityDependencyResolver();

            unityDependencyResolver.SetupDependencies();
            DependencyResolver.SetResolver(unityDependencyResolver);
        }
Exemplo n.º 26
0
        protected void Application_Start()
        {
            AreaRegistration.RegisterAllAreas();
            GlobalConfiguration.Configure(WebApiConfig.Register);
            FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
            RouteConfig.RegisterRoutes(RouteTable.Routes);
            UnityDependencyResolver.RegisterTypes();

            // Configures container for WebAPI
            GlobalConfiguration.Configuration.DependencyResolver = new Unity.WebApi.UnityDependencyResolver(UnityDependencyResolver.container);
            AutoMapperConfiguration.Configure();
        }
Exemplo n.º 27
0
        public static void RegisterComponents(HttpConfiguration config)
        {
            UnityContainer container = new UnityContainer();

            // register all your components with the container here


            //container.RegisterType<IUserEmailService, SendGridService>();
            container.RegisterType <IUserEmailService, MandrillService>();
            container.RegisterType <IUserRegistrationReport, UserRegistrationReport>();
            container.RegisterType <IJobsService, JobsService>();
            container.RegisterType <IJobsWaypointService, JobsWaypointService>();
            container.RegisterType <ITransactionLogService, TransactionLogService>();

            /* Note to GitHub Viewers: Many lines of code have been taken out of this file, so
             * I could showcase DI with Bringg Api */
            container.RegisterType(typeof(IBringgTask <>), typeof(CreateUser <>), "CreateUser");
            container.RegisterType(typeof(IBringgTask <>), typeof(UpdateUser <>), "UpdateUser");
            container.RegisterType(typeof(IBringgTask <>), typeof(DeleteUser <>), "DeleteUser");
            container.RegisterType(typeof(IBringgTask <>), typeof(CreateTask <>), "CreateTask");
            container.RegisterType(typeof(IBringgTask <>), typeof(CreateTaskWithWaypoints <>), "CreateTaskWithWaypoints");
            container.RegisterType(typeof(IBringgTask <>), typeof(CreateWaypoint <>), "CreateWaypoint");
            container.RegisterType(typeof(IBringgTask <>), typeof(UpdateCustomerTask <>), "UpdateCustomerTask");
            container.RegisterType(typeof(IBringgTask <>), typeof(UpdateTeamTask <>), "UpdateTeamTask");
            container.RegisterType(typeof(IBringgTask <>), typeof(DeleteTeamTask <>), "DeleteTeamTask");

            DependencyResolver.SetResolver(new UnityDependencyResolver(container));

            //  this line is needed so that the resolver can be used by api controllers
            config.DependencyResolver = new Bringpro.Web.Core.Injection.UnityResolver(container);

            var resolver = new UnityDependencyResolver(container);

            //container.RegisterType<IOutputService, OutputService>();


            DependencyResolver.SetResolver(resolver);

            DependencyResolver.SetResolver(new UnityDependencyResolver(container));


            //  this line is needed so that the resolver can be used by api controllers
            config.DependencyResolver = new UnityResolver(container);

            //  we have to make a custom filter injector to provide DI to our custom action filters.
            //  see http://michael-mckenna.com/blog/dependency-injection-for-asp-net-web-api-action-filters-in-3-easy-steps
            //var providers = config.Services.GetFilterProviders().ToList();

            //var defaultprovider = providers.Single(i => i is ActionDescriptorFilterProvider);
            //config.Services.Remove(typeof(System.Web.Http.Filters.IFilterProvider), defaultprovider);

            config.Services.Add(typeof(System.Web.Http.Filters.IFilterProvider), new UnityActionFilterProvider(container));
        }
        public void IsRegistered_Should_Return_False()
        {
            var resolver = new UnityDependencyResolver();

            resolver.RegisterType <IFace1, Class1>();
            resolver.RegisterType <IFace1, Class2>();
            resolver.RegisterInstance <IFace1>(new Class3());

            var result = resolver.IsRegistered <Class3>();

            Assert.IsFalse(result);
        }
Exemplo n.º 29
0
        public void UnityResolveSingleInstance()
        {
            var container = new UnityContainer();
            var registered = new Registered();
            container.RegisterInstance(registered);

            var resolver = new UnityDependencyResolver(container);

            var resolved = (Registered) resolver.GetInstance(typeof (Registered));

            Assert.That(resolved, Is.EqualTo(registered));
        }
Exemplo n.º 30
0
        public static void RegisterComponents()
        {
            var container = new UnityContainer();

            RegisterTypes(container);

            var resolver = new UnityDependencyResolver(container);

            GlobalConfiguration.Configuration.DependencyResolver = resolver;
            Core.REST.Resolver.DepResolver = resolver;
            Core.REST.Resolver.Container   = container;
        }
 public void When_resolving_unregistered_type_inside_scope_then_throws()
 {
     using (var container = new UnityContainer())
     {
         using (var resolver = new UnityDependencyResolver(container))
         {
             using (var scope = resolver.BeginScope())
             {
                 AssertThrows <ResolutionFailedException>(() => scope.GetService(typeof(IFoo)));
             }
         }
     }
 }
Exemplo n.º 32
0
 private static void RegisterTypes()
 {
     _dependencyResolver = new UnityDependencyResolver();
     _dependencyResolver.EnsureDependenciesRegistered();
     if (_useParallel)
     {
         _dependencyResolver.Container.RegisterType <INumbersToTextFile, NumbersToTextFileAsync>();
     }
     else
     {
         _dependencyResolver.Container.RegisterType(typeof(INumbersToTextFile), typeof(NumbersToTextFile));
     }
 }
Exemplo n.º 33
0
        protected void Application_Start()
        {
            AreaRegistration.RegisterAllAreas();
            FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
            RouteConfig.RegisterRoutes(RouteTable.Routes);
            BundleConfig.RegisterBundles(BundleTable.Bundles);
            GlobalConfiguration.Configure(WebApiConfig.Register);

            var globalConfig       = GlobalConfiguration.Configuration;
            var dependencyResolver = new UnityDependencyResolver(UnityConfig.Container);

            globalConfig.DependencyResolver = dependencyResolver;
        }
        public void When_resolving_type_with_container_controlled_lifetime_then_returns_same_instance_every_time()
        {
            using (var container = new UnityContainer())
            {
                container.RegisterType <IFoo, Foo>(new ContainerControlledLifetimeManager());
                var  resolver = new UnityDependencyResolver(container);
                IFoo resolve1 = (IFoo)resolver.GetService(typeof(IFoo));
                IFoo resolve2 = (IFoo)resolver.GetService(typeof(IFoo));

                Assert.IsNotNull(resolve1);
                Assert.AreSame(resolve1, resolve2);
            }
        }
        public void Array_Injector_Should_Inject_All_Registed_Types()
        {
            var resolver = new UnityDependencyResolver();
            resolver.RegisterType<IFace1, Class1>();
            resolver.RegisterType<IFace1, Class2>();
            resolver.RegisterInstance<IFace1>(new Class3());

            var resolve = resolver.Resolve<Class4>();
            Assert.AreEqual(3, resolve.Ifaces.Count());
            Assert.IsTrue(resolve.Ifaces.OfType<Class1>().Any());
            Assert.IsTrue(resolve.Ifaces.OfType<Class2>().Any());
            Assert.IsTrue(resolve.Ifaces.OfType<Class3>().Any());
        }
Exemplo n.º 36
0
        /// <summary>Integrates Unity when the application starts.</summary>
        public static void Start()
        {
            // Use UnityHierarchicalDependencyResolver if you want to use a new child container for each IHttpController resolution.
            // var resolver = new UnityHierarchicalDependencyResolver(UnityConfig.GetConfiguredContainer());
            var container = UnityConfig.GetConfiguredContainer();
            var resolver  = new UnityDependencyResolver(container);

            //Set resolver for MVC
            DependencyResolver.SetResolver(new Unity.Mvc5.UnityDependencyResolver(container));

            //Set resolver for Web API
            GlobalConfiguration.Configuration.DependencyResolver = resolver;
        }
        /// <summary>
        /// Integrates Unity when the application starts.
        /// </summary>
        public static void Start()
        {
            // Use UnityHierarchicalDependencyResolver if you want to use
            // a new child container for each IHttpController resolution.
            // var resolver = new UnityHierarchicalDependencyResolver(new UnityContainer());

            IUnityContainer container = new UnityContainer();
            //container.RegisterType<IRepository, EmployeeRepository>();
            var resolver = new UnityDependencyResolver(container);


            GlobalConfiguration.Configuration.DependencyResolver = resolver;
        }
        public void ResolveAll_Should_Return_All_Registed_Types()
        {
            var resolver = new UnityDependencyResolver();
            resolver.RegisterType<IFace1, Class1>();
            resolver.RegisterType<IFace1, Class2>();
            resolver.RegisterInstance<IFace1>(new Class3());

            var resolveAll = resolver.ResolveAll<IFace1>();
            Assert.Equal(3, resolveAll.Count());
            Assert.True(resolveAll.OfType<Class1>().Any());
            Assert.True(resolveAll.OfType<Class2>().Any());
            Assert.True(resolveAll.OfType<Class3>().Any());
        }
Exemplo n.º 39
0
        public void UnityResolveSingleInstance()
        {
            var container  = new UnityContainer();
            var registered = new Registered();

            container.RegisterInstance(registered);

            var resolver = new UnityDependencyResolver(container);

            var resolved = (Registered)resolver.GetInstance(typeof(Registered));

            Assert.That(resolved, Is.EqualTo(registered));
        }
        public void When_resolving_concrete_controller_then_returns_injected_instance()
        {
            using (var container = new UnityContainer())
            {
                container.RegisterInstance <IFoo>(new Foo {
                    TestProperty = "value"
                });
                var resolver = new UnityDependencyResolver(container);

                var actual = (TestController)resolver.GetService(typeof(TestController));
                Assert.AreEqual("value", actual.Foo.TestProperty);
            }
        }
        public void When_disposing_resolver_then_disposes_container()
        {
            using (var container = new UnityContainer())
            {
                container.RegisterInstance <IFoo>(new Foo {
                    TestProperty = "value"
                });
                var resolver = new UnityDependencyResolver(container);
                resolver.Dispose();

                // ObjectDisposedException?
                AssertThrows <ResolutionFailedException>(() => container.Resolve(typeof(IFoo)));
            }
        }
 public void When_resolving_then_returns_registered_instance()
 {
     using (var container = new UnityContainer())
     {
         container.RegisterInstance <IFoo>(new Foo {
             TestProperty = "value"
         });
         using (var resolver = new UnityDependencyResolver(container))
         {
             var actual = (IFoo)resolver.GetService(typeof(IFoo));
             Assert.AreEqual("value", actual.TestProperty);
         }
     }
 }
Exemplo n.º 43
0
        static Bootstrapper()
        {
            // Create our root container including the TypeTracker extension which OpenRasta
            // requires.  The extension doesn't change any behaviour for this container, but it
            // enables OpenRastas child container to do what it needs.
            Container = new UnityContainer();
            Container.AddNewExtension<TypeTracker>();

            // This is where you register all your normal application services that are designed to
            // work with Unity and its default injection policies.
            Container.RegisterType<IInfoProvider, InfoProvider>();

            // Create the resolver that OpenRasta will use for all dependencies.  This actually
            // creates a child container so it doesn't intefere with our application level
            // behaviour.
            Resolver = new UnityDependencyResolver(Container);
        }
Exemplo n.º 44
0
        private static void WithHashPool()
        {
            IUnityContainer container = new UnityContainer();
            container.RegisterType<TypedWorker>();


            using (var system = ActorSystem.Create("MySystem"))
            {
                var propsResolver =
                    new UnityDependencyResolver(container, system);

                var router = system.ActorOf(system.DI().Props<TypedWorker>().WithRouter(FromConfig.Instance), "router1");

                Task.Delay(500).Wait();
                Console.WriteLine("Sending Messages");

                for (var i = 0; i < 5; i++)
                {
                    for (var j = 0; j < 7; j++)
                    {

                        var msg = new TypedActorMessage { Id = j, Name = Guid.NewGuid().ToString() };
                        var ms = new AnotherMessage { Id = j, Name = msg.Name };

                        var envelope = new ConsistentHashableEnvelope(ms, msg.Id);

                        router.Tell(msg);
                        router.Tell(envelope);

                    }
                }
                Console.WriteLine("Hit Enter to exit");
                Console.ReadLine();
            }


        }
Exemplo n.º 45
0
 private void RegisterDependencyResolver(UnityDependencyResolver dependencyResolver)
 {
     DependencyResolver.SetResolver(dependencyResolver);
     GlobalConfiguration.Configuration.DependencyResolver = dependencyResolver;
 }
 public void ForCoverage()
 {
     IUnityContainer container = new UnityDependencyResolver().Container;
 }
Exemplo n.º 47
0
 public WebApiUnityDependencyResolver(UnityDependencyResolver resolver)
 {
     Resolver = resolver;
 }
        public void Unresolveable_Should_Return_Null()
        {
            var resolver = new UnityDependencyResolver();

            var result = resolver.Resolve<IFace1>();
            Assert.IsNull(result);
        }