Ejemplo n.º 1
0
                public object Get()
                {
                    if (singleton && cachedInstance != null)
                    {
                        return(cachedInstance);
                    }

                    try
                    {
                        var constructor = implementationType.GetConstructors().First();
                        var parameters  = constructor.GetParameters()
                                          .Select(p => container.GetType()
                                                  .GetMethod("Resolve")
                                                  .MakeGenericMethod(p.ParameterType).Invoke(container, new object[0]))
                                          .ToArray();

                        cachedInstance = Activator.CreateInstance(implementationType, parameters);

                        return(cachedInstance);
                    }
                    catch (Exception e)
                    {
                        throw new ApplicationException(string.Format("Could not resolve {0}", implementationType), e);
                    }
                }
        private void AssertGivesCorrectExceptionWhenResolvingRecursive <TService>(IContainerAdapter adapter)
        {
            try {
                adapter.Resolve <TService>();
            }
            catch (Exception ex) {
                Debug.WriteLine(adapter.GetType().Name + " throws following on recursion: " + ex);
                return;
            }

            throw new AssertException("No exception for recursion, either this use case is not supported or there is some other issue.");
        }