{"action":"created","issue":{"url":"https://api.github.com/repos/unitycontainer/microsoft-logging/issues/3","repository_url":"https://api.github.com/repos/unitycontainer/microsoft-logging","labels_url":"https://api.github.com/repos/unitycontainer/microsoft-logging/issues/3/labels{/name}","comments_url":"https://api.github.com/repos/unitycontainer/microsoft-logging/issues/3/comments","events_url":"https://api.github.com/repos/unitycontainer/microsoft-logging/issues/3/events","html_url":"https://github.com/unitycontainer/microsoft-logging/issues/3","id":360627978,"node_id":"MDU6SXNzdWUzNjA2Mjc5Nzg=","number":3,"title":"Could we make it optional to provide a ILoggerFactory and resolve it?","user":{"login":"pksorensen","id":2718591,"node_id":"MDQ6VXNlcjI3MTg1OTE=","avatar_url":"https://avatars2.githubusercontent.com/u/2718591?v=4","gravatar_id":"","url":"https://api.github.com/users/pksorensen","html_url":"https://github.com/pksorensen","followers_url":"https://api.github.com/users/pksorensen/followers","following_url":"https://api.github.com/users/pksorensen/following{/other_user}","gists_url":"https://api.github.com/users/pksorensen/gists{/gist_id}","starred_url":"https://api.github.com/users/pksorensen/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/pksorensen/subscriptions","organizations_url":"https://api.github.com/users/pksorensen/orgs","repos_url":"https://api.github.com/users/pksorensen/repos","events_url":"https://api.github.com/users/pksorensen/events{/privacy}","received_events_url":"https://api.github.com/users/pksorensen/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":2,"created_at":"2018-09-16T10:58:18Z","updated_at":"2018-09-16T15:04:52Z","closed_at":null,"author_association":"NONE","body":"My usecase is that the ILoggerFactory is build as part of startup and I want to lazy create it until the first ILogger is needed.\r\n\r\nI modified the extension\r\n```\r\npublic class LoggingExtension : UnityContainerExtension,\r\n                                   IBuildPlanCreatorPolicy,\r\n                                   IBuildPlanPolicy\r\n    {\r\n        #region Fields\r\n\r\n        private readonly MethodInfo _createLoggerMethod = typeof(LoggingExtension).GetTypeInfo()\r\n                                                                                  .GetDeclaredMethod(nameof(CreateLogger));\r\n\r\n        #endregion\r\n\r\n\r\n        #region Constructors\r\n\r\n        //[InjectionConstructor]\r\n        //public LoggingExtension()\r\n        //{\r\n        //    LoggerFactory = new LoggerFactory();\r\n        //}\r\n\r\n        //public LoggingExtension(ILoggerFactory factory)\r\n        //{\r\n        //    LoggerFactory = factory ?? new LoggerFactory();\r\n        //}\r\n\r\n\r\n        #endregion\r\n\r\n\r\n        #region Public Members\r\n\r\n        //public ILoggerFactory LoggerFactory { get; }\r\n\r\n        #endregion\r\n\r\n\r\n        #region IBuildPlanPolicy\r\n\r\n\r\n        public void BuildUp(IBuilderContext context)\r\n        {    \r\n            context.Existing = null == context.ParentContext\r\n                             ? context.ParentContext.Container.Resolve<ILoggerFactory>().CreateLogger(context.OriginalBuildKey.Name ?? string.Empty)\r\n                             : context.Container.Resolve<ILoggerFactory>().CreateLogger(context.ParentContext.BuildKey.Type);\r\n            context.BuildComplete = true;\r\n        }\r\n\r\n        #endregion\r\n\r\n\r\n        #region IBuildPlanCreatorPolicy\r\n\r\n        IBuildPlanPolicy IBuildPlanCreatorPolicy.CreatePlan(IBuilderContext context, INamedType buildKey)\r\n        {\r\n            var info = (context ?? throw new ArgumentNullException(nameof(context))).BuildKey\r\n                                                                                    .Type\r\n                                                                                    .GetTypeInfo();\r\n            if (!info.IsGenericType) return this;\r\n\r\n            var buildMethod = _createLoggerMethod.MakeGenericMethod(info.GenericTypeArguments.First())\r\n                                                 .CreateDelegate(typeof(DynamicBuildPlanMethod));\r\n\r\n            return new DynamicMethodBuildPlan((DynamicBuildPlanMethod)buildMethod, context.Container.Resolve<ILoggerFactory>());\r\n        }\r\n\r\n        #endregion\r\n\r\n\r\n        #region Implementation\r\n\r\n        private static void CreateLogger<T>(IBuilderContext context, ILoggerFactory loggerFactory)\r\n        {\r\n            context.Existing = loggerFactory.CreateLogger<T>();\r\n            context.BuildComplete = true;\r\n        }\r\n\r\n        protected override void Initialize()\r\n        {\r\n            Context.Policies.Set(typeof(ILogger), string.Empty, typeof(IBuildPlanPolicy), this);\r\n            Context.Policies.Set<IBuildPlanCreatorPolicy>(this, typeof(ILogger));\r\n            Context.Policies.Set<IBuildPlanCreatorPolicy>(this, typeof(ILogger<>));\r\n        }\r\n\r\n        private delegate void DynamicBuildPlanMethod(IBuilderContext context, ILoggerFactory loggerFactory);\r\n\r\n        private class DynamicMethodBuildPlan : IBuildPlanPolicy\r\n        {\r\n            private readonly DynamicBuildPlanMethod _buildMethod;\r\n            private readonly ILoggerFactory _loggerFactory;\r\n\r\n            /// <summary>\r\n            /// \r\n            /// </summary>\r\n            /// <param name=\"buildMethod\"></param>\r\n            /// <param name=\"loggerFactory\"></param>\r\n            public DynamicMethodBuildPlan(DynamicBuildPlanMethod buildMethod,\r\n                                          ILoggerFactory loggerFactory)\r\n            {\r\n                _buildMethod = buildMethod;\r\n                _loggerFactory = loggerFactory;\r\n            }\r\n\r\n            /// <summary>\r\n            /// \r\n            /// </summary>\r\n            /// <param name=\"context\"></param>\r\n            public void BuildUp(IBuilderContext context)\r\n            {\r\n                _buildMethod(context, _loggerFactory);\r\n            }\r\n        }\r\n\r\n        #endregion\r\n    }\r\n```\r\n\r\nWhat do you think, should we consider resolving it instead of giving it when constructing the extension?\r\n"},"comment":{"url":"https://api.github.com/repos/unitycontainer/microsoft-logging/issues/comments/421779429","html_url":"https://github.com/unitycontainer/microsoft-logging/issues/3#issuecomment-421779429","issue_url":"https://api.github.com/repos/unitycontainer/microsoft-logging/issues/3","id":421779429,"node_id":"MDEyOklzc3VlQ29tbWVudDQyMTc3OTQyOQ==","user":{"login":"ENikS","id":1750155,"node_id":"MDQ6VXNlcjE3NTAxNTU=","avatar_url":"https://avatars2.githubusercontent.com/u/1750155?v=4","gravatar_id":"","url":"https://api.github.com/users/ENikS","html_url":"https://github.com/ENikS","followers_url":"https://api.github.com/users/ENikS/followers","following_url":"https://api.github.com/users/ENikS/following{/other_user}","gists_url":"https://api.github.com/users/ENikS/gists{/gist_id}","starred_url":"https://api.github.com/users/ENikS/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ENikS/subscriptions","organizations_url":"https://api.github.com/users/ENikS/orgs","repos_url":"https://api.github.com/users/ENikS/repos","events_url":"https://api.github.com/users/ENikS/events{/privacy}","received_events_url":"https://api.github.com/users/ENikS/received_events","type":"User","site_admin":false},"created_at":"2018-09-16T15:04:52Z","updated_at":"2018-09-16T15:04:52Z","author_association":"MEMBER","body":"Resolving ILoggerFactroy is slow\r\n"}}
{"actor":{"display_login":"ENikS"}}