Ejemplo n.º 1
0
        private static void RegisterMappings(BindingRoot kernel)
        {
            kernel.Bind<IWebChatData>().To<WebChatData>()
                  .WithConstructorArgument(
                                           "context", 
                                           c => new WebChatDbContext());

            kernel.Bind<IUserIdProvider>().To<UserIdProvider>();
        }
Ejemplo n.º 2
0
        private static void RegisterMappings(BindingRoot kernel)
        {
            kernel.Bind <IWebChatData>().To <WebChatData>()
            .WithConstructorArgument(
                "context",
                c => new WebChatDbContext());

            kernel.Bind <IUserIdProvider>().To <UserIdProvider>();
        }
Ejemplo n.º 3
0
        public static IBindingInNamedWithOrOnSyntax <object> BindCommandHandler(
            BindingRoot bindingRoot, Type commandHandlerType, params Type[] services)
        {
            var handlerInterfaces = GetCommandHandlerInterfaces(commandHandlerType);
            var decoratorTypes    = GetPipelineDecoratorTypes(handlerInterfaces);

            foreach (var decoratorTypePair in decoratorTypes)
            {
                bindingRoot
                .Bind(decoratorTypePair.Key)
                .To(decoratorTypePair.Value)
                .InTaskScope();
            }

            return(bindingRoot
                   .Bind(handlerInterfaces.Concat(services).Concat(new[] { commandHandlerType }).ToArray())
                   .To(commandHandlerType)
                   .WhenInjectedInto(decoratorTypes.Values.ToArray()));
        }
 public static void Register(BindingRoot context)
 {
 }
Ejemplo n.º 5
0
 public BindingRootTests()
 {
     _bindingRoot = new MyBindingRoot();
 }
Ejemplo n.º 6
0
        /// <summary>
        /// Shortcut to bind a concrete type to an interface, both eagerly and lazily.
        /// </summary>
        /// <typeparam name="T1"></typeparam>
        /// <typeparam name="T2"></typeparam>
        /// <param name="root"></param>
        /// <param name="kernel"></param>
        /// <returns></returns>
        /// <remarks>
        /// Original implementation was accessing kernal from application cache. Kernel is now
        /// injected but this may not be the best way to implement.
        /// </remarks>
        public static EagerAndLazyBindingsWhenInNamedWithOrOnSyntax <T1, T2> FullBindTo <T1, T2>(this BindingRoot root, StandardKernel kernel)
            where T1 : class
            where T2 : class, T1
        {
            var eager = root.Bind <T1>().To <T2>();
            var lazy  = root.Bind <Lazy <T1> >().ToMethod(ctx => new Lazy <T1>(() => kernel.Get <T1>()));

            return(new EagerAndLazyBindingsWhenInNamedWithOrOnSyntax <T1, T2>(eager, lazy));
        }