示例#1
0
 public UnityResolver(Unity.IUnityContainer container)
 {
     if (container == null)
     {
         throw new ArgumentNullException("container");
     }
     this.container = container;
 }
 public static void AddKullDatabaseMetadata(this IServiceCollection services)
 {
     services.TryAddSingleton <ISPParameterProviderCache>(new SPParameterProviderMemoryCache());
     services.AddTransient <SqlHelper>();
     services.AddTransient <DBObjects>();
     services.AddTransient <Keys>();
     services.AddTransient <SPParametersProvider>();
 }
示例#3
0
        public ViewModelLocator()
        {
            _container = new UnityContainer();

            _container.RegisterType <MainPageViewModel>();

            _container.RegisterType <ILoaderService, LoaderService>(new ContainerControlledLifetimeManager());
            _container.RegisterType <INotaService, NotaService>(new ContainerControlledLifetimeManager());
            _container.RegisterType <IDialogService, DialogService>(new ContainerControlledLifetimeManager());
            _container.RegisterType <INavigationService, NavigationService>(new ContainerControlledLifetimeManager());
        }
示例#4
0
        /// <summary>
        /// Resolve all the registered instances of type T.
        /// </summary>
        /// <typeparam name="T"> Type </typeparam>
        /// <param name="container">The unity container instance.</param>
        /// <returns>Collection of resolve type T.</returns>
        /// <remarks>
        /// This extension method is a fix for the bug in unity ResolveAll Generic method.
        /// For more details follow the thread at "http://unity.codeplex.com/workitem/3392"
        /// </remarks>
        public static IEnumerable <T> ResolveAll <T>(this Unity.IUnityContainer container)
        {
            // IEnumerable <ContainerRegistration> names = container.Registrations.Where(registration => registration.RegisteredType == typeof(T));
            IEnumerable <IContainerRegistration> names = container.Registrations.Where(registration => registration.RegisteredType == typeof(T));


            foreach (ContainerRegistration registration in names)
            {
                //TODO yield return container.Resolve<T>(registration.Name);
            }

            return(null);
        }
示例#5
0
        /// <summary>
        /// Registers the type mappings with the Unity container.
        /// </summary>
        /// <param name="container">The unity container to configure.</param>
        /// <remarks>
        /// There is no need to register concrete types such as controllers or
        /// API controllers (unless you want to change the defaults), as Unity
        /// allows resolving a concrete type even if it was not previously
        /// registered.
        /// </remarks>
        public static void RegisterTypes(Unity.IUnityContainer container)
        {
            // NOTE: To load from web.config uncomment the line below.
            // Make sure to add a Unity.Configuration to the using statements.
            // container.LoadConfiguration();

            // TODO: Register your type's mappings here.
            container.RegisterType <IHubActivator, UnityHubActivator>(new ContainerControlledLifetimeManager());
            container.RegisterType <ITodoService, TodoService>(new PerResolveLifetimeManager());
            container.RegisterType <IToDoDbContext, GreenSlate.Database.ToDoTaskDbContext>(new PerResolveLifetimeManager());
            container.RegisterType <IToDoTasksHub, ToDoTasksHub>(new PerResolveLifetimeManager());

            // container.RegisterType<AccountController>(new InjectionConstructor());
            // container.RegisterType<ManageController>(new InjectionConstructor());
        }
        public static void RegisterInheritedTypes(this Unity.IUnityContainer container, Assembly assembly, System.Type baseType)
        {
            var allTypes       = assembly.GetTypes();
            var baseInterfaces = baseType.GetInterfaces();

            foreach (var type in allTypes)
            {
                var test = type.BaseType;
                if (type.BaseType != null && type.BaseType.GenericEq(baseType))
                {
                    var typeInterface = type.GetInterfaces().FirstOrDefault(x => !baseInterfaces.Any(bi => bi.GenericEq(x)));
                    if (typeInterface == null)
                    {
                        continue;
                    }
                    container.RegisterType(typeInterface, type);
                    //container.RegisterSingleton(typeInterface, type);
                }
            }

            var ok = assembly.GetTypes();
        }
 public UnityIoCContainer(IUnityContainer unityContainer)
 {
     _unityContainer = unityContainer;
 }
示例#8
0
 public GenericBackendBuilder(IServiceCollection services)
 {
     this.services = services;
 }