Пример #1
0
        public object Map(object entityObj)
        {
            Check.NotNull(entityObj, nameof(entityObj));

            var entity = entityObj as IEntity;

            if (entity == null)
            {
                return(null);
            }

            var entityType     = ProxyHelper.UnProxy(entity).GetType();
            var etoMappingItem = Options.EtoMappings.GetOrDefault(entityType);

            if (etoMappingItem == null)
            {
                var keys = entity.GetKeys().JoinAsString(",");
                return(new EntityEto(entityType.FullName, keys));
            }

            using (var scope = HybridServiceScopeFactory.CreateScope())
            {
                var objectMapperType = etoMappingItem.ObjectMappingContextType == null
                    ? typeof(IObjectMapper)
                    : typeof(IObjectMapper <>).MakeGenericType(etoMappingItem.ObjectMappingContextType);

                var objectMapper = (IObjectMapper)scope.ServiceProvider.GetRequiredService(objectMapperType);

                return(objectMapper.Map(entityType, etoMappingItem.EtoType, entityObj));
            }
        }
Пример #2
0
        protected virtual async Task <AllowedCorsOriginsCacheItem> CreateCacheItemAsync()
        {
            // doing this here and not in the ctor because: https://github.com/aspnet/AspNetCore/issues/2377
            using (var scope = HybridServiceScopeFactory.CreateScope()) {
                var clientRepository = scope.ServiceProvider.GetRequiredService <IClientRepository> ();

                return(new AllowedCorsOriginsCacheItem {
                    AllowedOrigins = (await clientRepository.GetAllDistinctAllowedCorsOriginsAsync()).ToArray()
                });
            }
        }
Пример #3
0
        /// <summary>
        /// Authenticate
        /// </summary>
        /// <param name="userDomainName">E.g [email protected] </param>
        /// <param name="password"></param>
        /// <returns></returns>
        public bool Authenticate(string userDomainName, string password)
        {
            try
            {
                using (GetConnection(userDomainName, password))
                {
                    return(true);
                }
            }
            catch (Exception ex)
            {
                using var scope = HybridServiceScopeFactory.CreateScope();
                scope.ServiceProvider
                .GetRequiredService <IExceptionNotifier>()
                .NotifyAsync(ex);

                return(false);
            }
        }