public override IComponentRegistry Register(Type dependencyType, Type implementationType, Lifestyle lifestyle)
        {
            Guard.AgainstNull(dependencyType, "dependencyType");
            Guard.AgainstNull(implementationType, "implementationType");

            base.Register(dependencyType, implementationType, lifestyle);

            try
            {
                switch (lifestyle)
                {
                case Lifestyle.Transient:
                {
                    _registry.For(dependencyType).Use(implementationType).Transient();

                    break;
                }

                default:
                {
                    _registry.ForSingletonOf(dependencyType).Use(implementationType).Singleton();

                    break;
                }
                }
            }
            catch (Exception ex)
            {
                throw new TypeRegistrationException(ex.Message, ex);
            }

            return(this);
        }
Exemple #2
0
 /// <summary>
 /// Configures the resolution of <typeparamref name="TDataContext"/>'s factory.
 /// </summary>
 /// <typeparam name="TDataContext">The DbContext.</typeparam>
 /// <param name="registry"></param>
 /// <param name="nameOrConnectionString">Name or connection string of the context. (Optional)</param>
 public static void AddDbContextFactory <TDataContext>(this IRegistry registry, string nameOrConnectionString = null)
     where TDataContext : DbContext
 {
     registry.For <Func <TDataContext> >().Use(
         DbContextFactory.Create <TDataContext>(nameOrConnectionString)
         );
 }
        public static void Register(IRegistry registry)
        {
            if(registry == null)
                throw new ArgumentNullException("registry");

            registry.For<IConfigurationManager>().Singleton().Use<ConfigurationManagerWrapper>();
        }
        private static void ConfigureClass(Type type, IRegistry registry, FireOptions fireOption, DependencyMap dependencyMap)
        {
            var inst = new LooseConstructorInstance(context =>
            {
                var ctorArgs = type
                    .GetGreediestCtor()
                    .GetParameters()
                    .Select(p => context.GetInstance(p.ParameterType));

                return Notifiable.MakeForClass(type, fireOption, ctorArgs.ToArray(), new ProxyGenerator(), dependencyMap);
            });

            registry.For(type).Use(inst);
        }
 private static void ConfigureInterface(Type type, IRegistry registry, FireOptions fireOption, DependencyMap dependencyMap)
 {
     registry
         .For(type)
         .EnrichWith((context, obj) => Notifiable.MakeForInterface(type, obj, fireOption, new ProxyGenerator(), dependencyMap));
 }
 public static SmartInstance <T> ForConcreteSingleton <T>(this IRegistry registry) => registry.For <T>().Singleton().Add <T>();
 public static SmartInstance <DataProvider <T, TContext> > ToContextAsQueryable <T, TContext>(this IRegistry registry)
     where T : class, IObjectWithState, new()
     where TContext : DbContext
 {
     return(registry.For <IQueryableDataProvider <T> >().HttpContextScoped().Use <DataProvider <T, TContext> >());
 }
        public static void Register(IRegistry registry)
        {
            if(registry == null)
                throw new ArgumentNullException("registry");

            registry.For<HttpApplicationState>().HybridHttpOrThreadLocalScoped().Use(() => HttpContext.Current.Application);
            registry.For<HttpApplicationStateBase>().HybridHttpOrThreadLocalScoped().Use<HttpApplicationStateWrapper>();
            registry.For<HttpContext>().HybridHttpOrThreadLocalScoped().Use(() => HttpContext.Current);
            registry.For<HttpContextBase>().HybridHttpOrThreadLocalScoped().Use<HttpContextWrapper>();
            registry.For<HttpRequest>().HybridHttpOrThreadLocalScoped().Use(() => HttpContext.Current.Request);
            registry.For<HttpRequestBase>().HybridHttpOrThreadLocalScoped().Use<HttpRequestWrapper>();
            registry.For<HttpResponse>().HybridHttpOrThreadLocalScoped().Use(() => HttpContext.Current.Response);
            registry.For<HttpResponseBase>().HybridHttpOrThreadLocalScoped().Use<HttpResponseWrapper>();
            registry.For<HttpServerUtility>().HybridHttpOrThreadLocalScoped().Use(() => HttpContext.Current.Server);
            registry.For<HttpServerUtilityBase>().HybridHttpOrThreadLocalScoped().Use<HttpServerUtilityWrapper>();
            registry.For<HttpSessionState>().HybridHttpOrThreadLocalScoped().Use(() => HttpContext.Current.Session);
            registry.For<HttpSessionStateBase>().HybridHttpOrThreadLocalScoped().Use<HttpSessionStateWrapper>();

            registry.For<IHtmlDocumentFactory>().Singleton().Use<DefaultHtmlDocumentFactory>();
            registry.For<IHtmlInvestigator>().Singleton().Use<DefaultHtmlInvestigator>();
            registry.For<IHtmlTransformerFactory>().Singleton().Use<DefaultHtmlTransformerFactory>();
            registry.For<IHtmlTransformingContext>().Singleton().Use<DefaultHtmlTransformingContext>();
            registry.For<IHtmlTransformingInitializer>().Singleton().Use<DefaultHtmlTransformingInitializer>();
        }
Exemple #9
0
 private static void AddSingleton <T, T2>(IRegistry x) where T2 : T
 {
     x.For <T>().Singleton().Use <T2>();
 }
Exemple #10
0
 private static void Add <T, T2>(IRegistry x) where T2 : T
 {
     x.For <T>().Use <T2>();
 }