Ejemplo n.º 1
0
        public static void ResolveByInterface <T>(string typeName, AppResolveDelegate <T> action)
        {
            if (!typeof(T).IsInterface)
            {
                throw new Exception(nameof(T) + " must be an interface.");
            }

            using (var scope = _container.BeginLifetimeScope())
            {
                string assemblyName = Assembly.GetExecutingAssembly().GetName().Name;
                typeName = typeName.Replace(assemblyName + ".", string.Empty);
                string @namespace = assemblyName + "." + typeName;
                var    resolved   = scope.ResolveKeyed <T>(@namespace);

                try
                {
                    action.Invoke(resolved);
                }
                catch (Exception ex)
                {
                    IErrorService errorService = scope.Resolve <IErrorService>();
                    errorService.LogError(ex, typeof(T).ToString());
                }
            }
        }
Ejemplo n.º 2
0
        public static T2 Resolve <T1, T2>(AppResolveDelegate <T1, T2> action)
        {
            T2 result;

            if (action == null)
            {
                throw new NullReferenceException(nameof(action));
            }

            using (var scope = _container.BeginLifetimeScope())
            {
                T1 resolved = (T1)scope.Resolve(typeof(T1));
                try
                {
                    result = action.Invoke(resolved);
                }
                catch (Exception ex)
                {
                    IErrorService errorService = scope.Resolve <IErrorService>();
                    errorService.LogError(ex, typeof(T1).ToString());
                    throw;
                }
            }

            return(result);
        }
Ejemplo n.º 3
0
        public static void Resolve <T>(AppResolveDelegate <T> action)
        {
            if (action == null)
            {
                throw new NullReferenceException(nameof(action));
            }

            using (var scope = _container.BeginLifetimeScope())
            {
                T resolved = (T)scope.Resolve(typeof(T));

                try
                {
                    action.Invoke(resolved);
                }
                catch (Exception ex)
                {
                    IErrorService errorService = scope.Resolve <IErrorService>();
                    errorService.LogError(ex, typeof(T).ToString());
                }
            }
        }