Exemple #1
0
        public void AfterPropertiesSet(IBeanContextFactory beanContextFactory)
        {
            IBeanConfiguration dummyServiceBC = beanContextFactory.RegisterBean <DummyService>(DUMMY_CACHE_SERVICE).Autowireable(typeof(IClientServiceFactory), typeof(ICacheRetriever));

            beanContextFactory.RegisterAlias(CacheModule.EXTERNAL_CACHE_SERVICE, DUMMY_CACHE_SERVICE);
            beanContextFactory.Link(dummyServiceBC).To <IMergeServiceExtensionExtendable>().With(typeof(Object));


            beanContextFactory.RegisterAlias(CacheModule.ROOT_CACHE_RETRIEVER, "cacheServiceRegistry");
        }
Exemple #2
0
        public virtual void AfterPropertiesSet(IBeanContextFactory beanContextFactory)
        {
            ParamChecker.AssertNotNull(RevertChangesHelper, "RevertChangesHelper");
            ParamChecker.AssertNotNull(SharedData, "SharedData");
            ParamChecker.AssertNotNull(SharedDataHandOnExtendable, "SharedDataHandOnExtendable");

            //TODO: inject Uri as bean
#if SILVERLIGHT
            Uri uri = HtmlPage.Document.DocumentUri;
#else
            Uri uri = null;
            if (uri == null)
            {
                throw new NotSupportedException("This code has to be compatible with .NET first");
            }
#endif

            ISet <String> allBeanNames = new HashSet <String>();
            if (BeansToConsume != null)
            {
                allBeanNames.UnionWith(BeansToConsume.Keys);
            }

            IDictionary <String, IModelContainer> data = null;
            if (Token != null)
            {
                data = SharedData.Read(Token);
            }
            if (data == null)
            {
                // Clear token to suppress handsOn in afterStarted()
                Token = null;
                data  = new Dictionary <String, IModelContainer>();
            }
            IModelMultiContainer <Uri> uriList = (IModelMultiContainer <Uri>)DictionaryExtension.ValueOrDefault(data, SourceUriBeanName);
            if (uriList != null)
            {
                //Url-list is avaliable
                uriList.Values.Add(uri);
            }
            allBeanNames.UnionWith(data.Keys);

            if (!allBeanNames.Contains(SourceUriBeanName))
            {
                //Url-list is not avaliable
                beanContextFactory.RegisterBean <ModelMultiContainer <Uri> >(SourceUriBeanName).PropertyValue("Value", uri);
            }

            IdentityHashSet <Object> allProvidedBusinessObjects = new IdentityHashSet <Object>();
            foreach (String nameInOwnContext in allBeanNames)
            {
                //Proecess the input
                IModelContainer dataContainer = DictionaryExtension.ValueOrDefault(data, nameInOwnContext);
                if (dataContainer != null)
                {
                    if (dataContainer is IModelMultiContainer)
                    {
                        IEnumerable businessObjects = ((IModelMultiContainer)dataContainer).ValuesData;
                        if (businessObjects != null)
                        {
                            allProvidedBusinessObjects.AddAll(businessObjects.Cast <object>());
                        }
                    }
                    else if (dataContainer is IModelSingleContainer)
                    {
                        Object businessObject = ((IModelSingleContainer)dataContainer).ValueData;
                        if (businessObject != null)
                        {
                            allProvidedBusinessObjects.Add(businessObject);
                        }
                    }
                    //By copying only the data, listeners are unregistered
                    //beanContextFactory.registerBean(name, dataContainer.GetType()).propertyValue("Data", dataContainer.Data);
                    beanContextFactory.RegisterExternalBean(nameInOwnContext, dataContainer);
                    continue;
                }
                if (!BeansToConsume.ContainsKey(nameInOwnContext))
                {
                    continue;
                }
                //Process default-beans
                String aliasToDefaultBean = BeansToConsume[nameInOwnContext];
                if (aliasToDefaultBean == null)
                {
                    //Mandatory parameter was not present in data
                    throw new Exception("The new Screen has not all mandatory information: \"" + nameInOwnContext + "\" is missing.");
                }
                if (!nameInOwnContext.Equals(aliasToDefaultBean))
                {
                    beanContextFactory.RegisterAlias(nameInOwnContext, aliasToDefaultBean);
                }
            }
            if (allProvidedBusinessObjects.Count > 0)
            {
                IRevertChangesSavepoint savepoint = RevertChangesHelper.CreateSavepoint(allProvidedBusinessObjects);
                beanContextFactory.RegisterExternalBean(savepoint).Autowireable <IRevertChangesSavepoint>();
            }
        }
Exemple #3
0
        public void AfterPropertiesSet(IBeanContextFactory beanContextFactory)
        {
            ParamChecker.AssertNotNull(ProxyFactory, "ProxyFactory");

            IBeanConfiguration serviceResultcache = beanContextFactory.RegisterBean <ServiceResultCache>().Autowireable <IServiceResultCache>();

            beanContextFactory.Link(serviceResultcache, "HandleClearAllCaches").To <IEventListenerExtendable>().With(typeof(ClearAllCachesEvent));

            beanContextFactory.RegisterBean <ValueHolderIEC>().Autowireable(typeof(ValueHolderIEC), typeof(IProxyHelper));

            beanContextFactory.RegisterBean <CacheHelper>().Autowireable(typeof(ICacheHelper), typeof(ICachePathHelper), typeof(IPrefetchHelper));

            IBeanConfiguration prioMembersProvider = beanContextFactory.RegisterBean <PrioMembersProvider>().Autowireable <IPrioMembersProvider>();

            beanContextFactory.Link(prioMembersProvider, PrioMembersProvider.handleMetaDataAddedEvent).To <IEventListenerExtendable>()
            .With(typeof(IEntityMetaDataEvent));

            beanContextFactory.RegisterBean <CacheWalker>().Autowireable <ICacheWalker>();

            beanContextFactory.RegisterAutowireableBean <ICacheMapEntryTypeProvider, CacheMapEntryTypeProvider>();

            beanContextFactory.RegisterAutowireableBean <IRootCacheValueFactory, RootCacheValueFactory>();

            //IBeanConfiguration rootCache = beanContextFactory.registerBean<RootCache>("rootCache").autowireable(typeof(RootCache), typeof(IWritableCache));
            //if (IsUseSingleChildCache)
            //{
            //    beanContextFactory.registerBean<SingletonCacheFactory>("cacheFactory")
            //        .propertyRefs("singletonChildCache")
            //        .autowireable<ICacheFactory>();

            //    IWritableCache childCache = (IWritableCache)beanContextFactory.registerBean<ChildCache>("singletonChildCache")
            //        .propertyRefs("rootCache")
            //        .autowireable(typeof(ICache)).GetInstance();

            //    ((RootCache)rootCache.GetInstance()).AddChildCache(childCache);
            //}
            //else
            //{
            //    rootCache.autowireable(typeof(ICache), typeof(IWritableCache), typeof(ICacheFactory));
            //}

            //beanContextFactory.registerBean<RootCache>(ROOT_CACHE).autowireable<RootCache>();
            //beanContextFactory.Link("rootCache").To<IOfflineListenerExtendable>();

            beanContextFactory.RegisterBean <CacheRetrieverRegistry>(ROOT_CACHE_RETRIEVER).Autowireable(typeof(ICacheServiceByNameExtendable), typeof(ICacheRetrieverExtendable));

            beanContextFactory.RegisterBean <FirstLevelCacheManager>("firstLevelCacheManager").Autowireable(typeof(IFirstLevelCacheExtendable), typeof(IFirstLevelCacheManager));

            String rootCacheBridge = "rootCacheBridge";

            beanContextFactory.RegisterBean <RootCacheBridge>(rootCacheBridge).PropertyRefs(COMMITTED_ROOT_CACHE, ROOT_CACHE_RETRIEVER);

            TransactionalRootCacheInterceptor txRcInterceptor = new TransactionalRootCacheInterceptor();

            beanContextFactory.RegisterWithLifecycle("txRootCacheInterceptor", txRcInterceptor).PropertyRefs(COMMITTED_ROOT_CACHE, rootCacheBridge)
            .Autowireable(typeof(ITransactionalRootCache), typeof(ISecondLevelCacheManager));

            Object txRcProxy = ProxyFactory.CreateProxy(new Type[] { typeof(IRootCache), typeof(ICacheIntern), typeof(IOfflineListener) }, txRcInterceptor);

            beanContextFactory.RegisterExternalBean(ROOT_CACHE, txRcProxy).Autowireable(typeof(IRootCache), typeof(ICacheIntern));

            if (IsSecondLevelCacheActive)
            {
                // One single root cache instance for whole context
                beanContextFactory.RegisterBean <RootCache>(COMMITTED_ROOT_CACHE).PropertyRef("CacheRetriever", ROOT_CACHE_RETRIEVER)
                .PropertyValue("Privileged", true);
                beanContextFactory.Link(CacheModule.COMMITTED_ROOT_CACHE).To <IOfflineListenerExtendable>();
            }
            else
            {
                // One root cache instance per thread sequence. Most often used in server environment where the "deactivated"
                // second level cache means that each thread hold his own, isolated root cache (which gets cleared with each service
                // request. Effectively this means that the root cache itself only lives per-request and does not hold a longer state
                IInterceptor threadLocalRootCacheInterceptor = (IInterceptor)beanContextFactory
                                                               .RegisterBean <ThreadLocalRootCacheInterceptor>("threadLocalRootCacheInterceptor")
                                                               .PropertyRef("StoredCacheRetriever", CacheModule.ROOT_CACHE_RETRIEVER).PropertyValue("Privileged", true).GetInstance();

                RootCache rootCacheProxy = ProxyFactory.CreateProxy <RootCache>(threadLocalRootCacheInterceptor);

                beanContextFactory.RegisterExternalBean(CacheModule.COMMITTED_ROOT_CACHE, rootCacheProxy).Autowireable <RootCache>();
            }
            beanContextFactory.RegisterBean <CacheEventTargetExtractor>("cacheEventTargetExtractor");
            beanContextFactory.Link("cacheEventTargetExtractor").To <IEventTargetExtractorExtendable>().With(typeof(ICache));

            beanContextFactory.RegisterBean <CacheFactory>().Autowireable <ICacheFactory>();

            IInterceptor cacheProviderInterceptor = (IInterceptor)beanContextFactory
                                                    .RegisterBean <CacheProviderInterceptor>("cacheProviderInterceptor")
                                                    .Autowireable(typeof(ICacheProviderExtendable), typeof(ICacheProvider), typeof(ICacheContext)).GetInstance();

            ICache cacheProxy = ProxyFactory.CreateProxy <ICache>(new Type[] { typeof(ICacheProvider), typeof(IWritableCache) }, cacheProviderInterceptor);

            beanContextFactory.RegisterExternalBean("cache", cacheProxy).Autowireable <ICache>();

            beanContextFactory.RegisterBean <PagingQueryServiceResultProcessor>("pagingQuerySRP");
            beanContextFactory.Link("pagingQuerySRP").To <IServiceResultProcessorExtendable>().With(typeof(IPagingResponse));

            beanContextFactory.RegisterBean <CacheProvider>(CacheNamedBeans.CacheProviderSingleton).PropertyValue("CacheType", CacheType.SINGLETON);

            beanContextFactory.RegisterBean <CacheProvider>(CacheNamedBeans.CacheProviderThreadLocal).PropertyValue("CacheType", CacheType.THREAD_LOCAL);

            beanContextFactory.RegisterBean <CacheProvider>(CacheNamedBeans.CacheProviderPrototype).PropertyValue("CacheType", CacheType.PROTOTYPE);

            String defaultCacheProviderBeanName;

            switch (DefaultCacheType)
            {
            case CacheType.PROTOTYPE:
            {
                defaultCacheProviderBeanName = CacheNamedBeans.CacheProviderPrototype;
                break;
            }

            case CacheType.SINGLETON:
            {
                defaultCacheProviderBeanName = CacheNamedBeans.CacheProviderSingleton;
                break;
            }

            case CacheType.THREAD_LOCAL:
            {
                defaultCacheProviderBeanName = CacheNamedBeans.CacheProviderThreadLocal;
                break;
            }

            case CacheType.DEFAULT:
            {
                defaultCacheProviderBeanName = CacheNamedBeans.CacheProviderThreadLocal;
                break;
            }

            default:
                throw new Exception("Not supported type: " + DefaultCacheType);
            }
            beanContextFactory.Link(defaultCacheProviderBeanName).To <ICacheProviderExtendable>();

            // CacheContextPostProcessor must be registered AFTER CachePostProcessor...
            Object cachePostProcessor = beanContextFactory.RegisterBean <CachePostProcessor>().GetInstance();

            beanContextFactory.RegisterBean <CacheContextPostProcessor>().PropertyValue("CachePostProcessor", cachePostProcessor);

            if (IsNetworkClientMode && IsCacheServiceBeanActive)
            {
                IBeanConfiguration remoteCacheService = beanContextFactory.RegisterBean <ClientServiceBean>(CacheModule.EXTERNAL_CACHE_SERVICE)
                                                        .PropertyValue("Interface", typeof(ICacheService))
                                                        .PropertyValue("SyncRemoteInterface", typeof(ICacheServiceWCF))
                                                        .PropertyValue("AsyncRemoteInterface", typeof(ICacheClient)).Autowireable <ICacheService>();

                beanContextFactory.RegisterAlias(CacheModule.DEFAULT_CACHE_RETRIEVER, CacheModule.EXTERNAL_CACHE_SERVICE);

                // register to all entities in a "most-weak" manner
                beanContextFactory.Link(remoteCacheService).To <ICacheRetrieverExtendable>().With(typeof(Object));
                //beanContextFactory.RegisterAlias(CacheModule.ROOT_CACHE_RETRIEVER, CacheModule.EXTERNAL_CACHE_SERVICE);
                //beanContextFactory.registerBean<CacheServiceDelegate>("cacheService").autowireable<ICacheService>();
            }
            beanContextFactory.RegisterBean <DataObjectMixin>().Autowireable <DataObjectMixin>();
            beanContextFactory.RegisterBean <EntityEqualsMixin>().Autowireable <EntityEqualsMixin>();
            beanContextFactory.RegisterBean <EmbeddedTypeMixin>().Autowireable <EmbeddedTypeMixin>();
            beanContextFactory.RegisterBean <PropertyChangeMixin>().Autowireable(typeof(PropertyChangeMixin),
                                                                                 typeof(IPropertyChangeExtensionExtendable), typeof(ICollectionChangeExtensionExtendable));
            beanContextFactory.RegisterBean <ValueHolderContainerMixin>().Autowireable <ValueHolderContainerMixin>();
        }