{"action":"created","issue":{"url":"https://api.github.com/repos/aspnetboilerplate/aspnetboilerplate/issues/339","labels_url":"https://api.github.com/repos/aspnetboilerplate/aspnetboilerplate/issues/339/labels{/name}","comments_url":"https://api.github.com/repos/aspnetboilerplate/aspnetboilerplate/issues/339/comments","events_url":"https://api.github.com/repos/aspnetboilerplate/aspnetboilerplate/issues/339/events","html_url":"https://github.com/aspnetboilerplate/aspnetboilerplate/issues/339","id":57899675,"number":339,"title":"Load localization data from DB","user":{"login":"lemestrez","id":9674445,"avatar_url":"https://avatars.githubusercontent.com/u/9674445?v=3","gravatar_id":"","url":"https://api.github.com/users/lemestrez","html_url":"https://github.com/lemestrez","followers_url":"https://api.github.com/users/lemestrez/followers","following_url":"https://api.github.com/users/lemestrez/following{/other_user}","gists_url":"https://api.github.com/users/lemestrez/gists{/gist_id}","starred_url":"https://api.github.com/users/lemestrez/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/lemestrez/subscriptions","organizations_url":"https://api.github.com/users/lemestrez/orgs","repos_url":"https://api.github.com/users/lemestrez/repos","events_url":"https://api.github.com/users/lemestrez/events{/privacy}","received_events_url":"https://api.github.com/users/lemestrez/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/aspnetboilerplate/aspnetboilerplate/labels/question","name":"question","color":"bbbbbb"}],"state":"closed","locked":false,"assignee":null,"milestone":null,"comments":11,"created_at":"2015-02-17T09:10:40Z","updated_at":"2015-05-04T06:34:38Z","closed_at":"2015-02-27T13:56:02Z","body":"Hi,\r\n\r\nin  #333 is described, how i can load the languages from from DB. In the next step I want to load the localization data from DB.\r\n\r\nSo i tried to write an own \"DictionaryBasedLocalizationSource\":\r\n\r\n    /// <summary>\r\n    /// Database based localization source.\r\n    /// </summary>\r\n    public class DbLocalizationSource : DictionaryBasedLocalizationSource, ISingletonDependency\r\n    {\r\n        public DbLocalizationSource(string name)\r\n            : base(name)\r\n        {\r\n        }\r\n\r\n        public override void Initialize()\r\n        {\r\n            var cultureRepository = IocManager.Instance.Resolve<ICultureService>();\r\n            var labelTextRepository = IocManager.Instance.Resolve<ITranslationService>();\r\n\r\n            var cultures = cultureRepository.GetCultureList(new GetCultureListInput()).Cultures;\r\n\r\n            var entries = labelTextRepository.GeLabelTextList(new GetLabelTextListInput()).LabelText;\r\n\r\n            foreach(var culture in cultures)\r\n            {\r\n                ILocalizationDictionary dictionary = DbLocalizationDictionary.Build(culture, entries);\r\n                AddDictionary(dictionary);\r\n            }\r\n\r\n            IocManager.Instance.Release(labelTextRepository);\r\n            IocManager.Instance.Release(cultureRepository);\r\n        }\r\n    }\r\n\r\nAnd an own \"LocalizationDictionary\":\r\n\r\n    public class DbLocalizationDictionary : LocalizationDictionary\r\n    {\r\n        #region Constructor\r\n        /// <summary>\r\n        /// Private constructor\r\n        /// </summary>\r\n        /// <param name=\"cultureInfo\">Culture of the dictionary</param>\r\n        private DbLocalizationDictionary(CultureInfo cultureInfo)\r\n            : base(cultureInfo)\r\n        {\r\n        }\r\n        #endregion\r\n\r\n        #region Public static methods\r\n        /// <summary>\r\n        /// Builds an <see cref=\"DbLocalizationDictionary\"/> from given file.\r\n        /// </summary>\r\n        public static DbLocalizationDictionary Build(CultureInfo cultureInfo, IEnumerable<LabelTextDto> labelTextEntries)\r\n        {\r\n            try\r\n            {\r\n                DbLocalizationDictionary dictionary = new DbLocalizationDictionary(cultureInfo);\r\n\r\n                foreach(var entry in labelTextEntries)\r\n                {\r\n                    var i18n = entry.I18n.FirstOrDefault(x => x.Culture == cultureInfo);\r\n\r\n                    if (i18n == null)\r\n                    {\r\n                        i18n = entry.I18n.FirstOrDefault(x => x.Culture.Name == \"de-DE\");\r\n                    }\r\n\r\n                    dictionary[entry.Symbol] = i18n.Text;\r\n                }\r\n\r\n                return dictionary;\r\n            }\r\n            catch (Exception ex)\r\n            {\r\n                throw new AbpException(\"Exception in DataAccess for localization!\", ex);\r\n            }\r\n        }\r\n        #endregion\r\n    }\r\n\r\nI want to add the source in the WebModule:\r\n\r\n            Configuration.Localization.Sources.Add(\r\n                new DbLocalizationSource(\r\n                    \"Test\"\r\n                    )\r\n                );\r\n\r\nI can't add the source in \"PreInitialize\", because at this time i can't resolve the needed services.\r\nIn \"Initialize\" it is to late, because the datasources needed before this time (in ControllerBase:AbpController => At the assign time for the LocalizationSourceName)\r\n\r\nHow can i realize a DB based localization source?"},"comment":{"url":"https://api.github.com/repos/aspnetboilerplate/aspnetboilerplate/issues/comments/98597244","html_url":"https://github.com/aspnetboilerplate/aspnetboilerplate/issues/339#issuecomment-98597244","issue_url":"https://api.github.com/repos/aspnetboilerplate/aspnetboilerplate/issues/339","id":98597244,"user":{"login":"Chris159","id":10975331,"avatar_url":"https://avatars.githubusercontent.com/u/10975331?v=3","gravatar_id":"","url":"https://api.github.com/users/Chris159","html_url":"https://github.com/Chris159","followers_url":"https://api.github.com/users/Chris159/followers","following_url":"https://api.github.com/users/Chris159/following{/other_user}","gists_url":"https://api.github.com/users/Chris159/gists{/gist_id}","starred_url":"https://api.github.com/users/Chris159/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Chris159/subscriptions","organizations_url":"https://api.github.com/users/Chris159/orgs","repos_url":"https://api.github.com/users/Chris159/repos","events_url":"https://api.github.com/users/Chris159/events{/privacy}","received_events_url":"https://api.github.com/users/Chris159/received_events","type":"User","site_admin":false},"created_at":"2015-05-04T06:34:37Z","updated_at":"2015-05-04T06:34:37Z","body":"Hi, thanks for your answer, but if I add it in initialize, following error occurs (I updated Abp and all dependencies to newest version 0.5.13)\r\n\r\n[HandlerException: Can't create component 'Abp.Auditing.AuditingInterceptor' as it has dependencies to be satisfied.\r\n\r\n'Abp.Auditing.AuditingInterceptor' is waiting for the following dependencies:\r\n\r\nService 'Abp.Auditing.IAuditingStore' which was not registered. ] Castle.MicroKernel.Handlers.DefaultHandler.AssertNotWaitingForDependency() +63 Castle.MicroKernel.Handlers.DefaultHandler.ResolveCore(CreationContext context, Boolean requiresDecommission, Boolean instanceRequired, Burden& burden) +513 Castle.MicroKernel.Handlers.DefaultHandler.Resolve(CreationContext context, Boolean instanceRequired) +55 Castle.MicroKernel.Handlers.AbstractHandler.Resolve(CreationContext context) +46 Castle.Core.InterceptorReference.Castle.MicroKernel.IReference.Resolve(IKernel kernel, CreationContext context) +363 Castle.Windsor.Proxy.AbstractProxyFactory.ObtainInterceptors(IKernel kernel, ComponentModel model, CreationContext context) +596 Castle.Windsor.Proxy.DefaultProxyFactory.Create(IKernel kernel, Object target, ComponentModel model, CreationContext context, Object[] constructorArguments) +112 Castle.MicroKernel.ComponentActivator.DefaultComponentActivator.CreateInstance(CreationContext context, ConstructorCandidate constructor, Object[] arguments) +688\r\n[ComponentActivatorException: ComponentActivator: could not proxy test.Configurations.GlobalLanguages.GlobalLanguagesAppService]\r\nCastle.MicroKernel.ComponentActivator.DefaultComponentActivator.CreateInstance(CreationContext context, ConstructorCandidate constructor, Object[] arguments) +975\r\nCastle.MicroKernel.ComponentActivator.DefaultComponentActivator.Instantiate(CreationContext context) +114\r\nCastle.MicroKernel.ComponentActivator.DefaultComponentActivator.InternalCreate(CreationContext context) +49\r\nCastle.MicroKernel.ComponentActivator.AbstractComponentActivator.Create(CreationContext context, Burden burden) +55\r\nCastle.MicroKernel.Lifestyle.AbstractLifestyleManager.CreateInstance(CreationContext context, Boolean trackedExternally) +117\r\nCastle.MicroKernel.Lifestyle.AbstractLifestyleMana"}}