{"id":19068449,"url":"https://github.com/bobbylite/.netcorelibrary","last_synced_at":"2025-07-06T16:37:39.466Z","repository":{"id":38093771,"uuid":"240482273","full_name":"bobbylite/.NETCoreLibrary","owner":"bobbylite","description":".NET Core solution for bobbylite library toolkit.","archived":false,"fork":false,"pushed_at":"2022-12-08T09:42:48.000Z","size":1620,"stargazers_count":0,"open_issues_count":1,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-01-02T15:19:20.077Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"C#","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/bobbylite.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2020-02-14T10:22:12.000Z","updated_at":"2020-02-17T06:13:29.000Z","dependencies_parsed_at":"2023-01-25T01:15:48.418Z","dependency_job_id":null,"html_url":"https://github.com/bobbylite/.NETCoreLibrary","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bobbylite%2F.NETCoreLibrary","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bobbylite%2F.NETCoreLibrary/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bobbylite%2F.NETCoreLibrary/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bobbylite%2F.NETCoreLibrary/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/bobbylite","download_url":"https://codeload.github.com/bobbylite/.NETCoreLibrary/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":240122465,"owners_count":19751139,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-09T01:08:29.387Z","updated_at":"2025-02-22T03:29:28.697Z","avatar_url":"https://github.com/bobbylite.png","language":"C#","funding_links":[],"categories":[],"sub_categories":[],"readme":"# bobbylite toolkit for .NET Core [![Tweet](https://img.shields.io/twitter/url/http/shields.io.svg?style=social)](https://twitter.com/intent/tweet?text=bobbylite%20.NET%20Core%20toolkit\u0026url=https://github.com/bobbylite/.NETCoreLibrary\u0026hashtags=Inversion-of-Control,Events,Autofac,bobbylite)\nbobbylite toolkit is a class library that utilizes inversion of control dependency injection.\n\n## Run example\nThere is a test script available to run to see how this repo works. \nRun the following in your terminal.\n\n### Clone the code \n```bash\ngit clone https://github.com/bobbylite/.NETCoreLibrary.git\ncd .NETCoreLibrary/\n```\n### .NET Reference Guide\nhttps://docs.microsoft.com/en-us/dotnet/core/tools/dotnet-add-reference\n\n\n### Hot to build\n```bash\ndotnet build\n```\n\n### How to run\n```bash\ndotnet test bobbylite-test/bobbylite-test.csproj\n```\n\n## How to use in project\n\n### Step 1\nImplement your Event so you can have everything you need.  Maybe you want to setup a service for handling an event later?  \n```csharp \nusing bobbylite.Notifications;\n\nnamespace bobbylite {\n    public class ApplicationStartedNotification : IAppNotification {\n\n    }\n}\n```\n\n### Step 2\nThis is where we will implement our event handler.  We must make sure to inherit the ApplicationHandler\u003cT\u003e class provided. \n```csharp\nusing System;\nusing bobbylite.Handlers;\n\nnamespace bobbylite {\n    public class ApplicationStartedNotificationHandler : ApplicationHandler\u003cApplicationStartedNotification\u003e {\n        protected override void HandleNotification(ApplicationStartedNotification message) {\n            Console.WriteLine(\"Application Started Successfully...\");\n        }\n    }\n}\n```\n\n### Step 3\n```csharp\nusing System;\nusing bobbylite.Notifications;\nusing Autofac;\n\nnamespace bobbylite {\n    public class ApplicationStartupService : IAutoStart {\n\n        public NotificationManager NotificationManager {get; set;}\n\n        public void Start() =\u003e NotificationManager.Notify(new ApplicationStartedNotification());\n    }\n}\n```\n\n### Step 4\nNow we need to wire up/connect the ApplicationStartedEvent to the ApplicationStartedEventHandler and the ApplicationStartupService that inherits IAutoStart.\n```csharp\nusing System.Reflection;\nusing Autofac;\nusing Module = Autofac.Module;\nusing bobbylite.Notifications;\n\nnamespace bobbylite {\n    public class ApplicationModule : Module {\n        protected override void Load(ContainerBuilder builder) {\n            StartUp(builder);\n            StartNotificationManager(builder);\n        }\n\n        private void StartUp(ContainerBuilder builder) {\n            builder.Register(c =\u003e new ApplicationStartupService())\n                .As\u003cIAutoStart\u003e()\n                .SingleInstance()\n                .PropertiesAutowired(PropertyWiringOptions.AllowCircularDependencies);\n        }\n\n        private void StartNotificationManager(ContainerBuilder builder) {\n            builder.RegisterType\u003cApplicationStartedNotificationHandler\u003e()\n                .As\u003cIHandleNotifications\u003cApplicationStartedNotification\u003e\u003e()\n                .PropertiesAutowired()\n                .SingleInstance();\n        }\n    }\n}\n```\n\n### Step 5\nLastly we will build the Autofac container. This is the entry point to the toolkit.\nBelow is an example of my test code. \n```csharp\nusing System;\nusing System.Threading.Tasks;\nusing Xunit;\nusing bobbylite;\nusing bobbylite.DependencyInjection;\nusing Autofac;\n\nnamespace bobbylite\n{\n    public class UnitTest1\n    {\n        private IContainer _container;\n\n        [Fact]\n        public void Test1()\n        {\n            var builder = new ContainerBuilder();\n            builder.RegisterModule(new bobbylite.DependencyInjection.Modules.CoreModule());\n            builder.RegisterModule(new ApplicationModule());\n            _container = builder.Build();\n\n            AutoStart();\n        }\n\n        private void AutoStart() {\n            var resolved = _container.Resolve\u003cObjectResolver\u003e();\n            foreach(var instance in resolved.GetAll\u003cIAutoStart\u003e()) {\n                Task.Run(() =\u003e {\n                    try {\n                        instance.Start();\n                    } catch (Exception) {\n                        // Handle exception\n                    }\n                });\n            }\n        }\n    }\n}\n```\n\n## Behind the scenes\nBehind the scenes we have two important files that really auto-wire up the notifications to the handlers.\nThis .NET Core lib uses Autofac's container and interfaces to auto-wire everything in the background. Out of the box\nyou have NotificationManager because of this Core Module in the lib. \nTake a look below.\n\n#### Core Module\n```csharp\nusing Autofac;\nusing bobbylite.Notifications;\n\nnamespace bobbylite.DependencyInjection.Modules\n{\n    public class CoreModule : Module\n    {\n        protected override void Load(ContainerBuilder builder)\n        {\n            builder.Register(c =\u003e new ObjectResolver(c.Resolve\u003cIComponentContext\u003e())).AsSelf().SingleInstance();\n            builder.RegisterType\u003cNotificationManager\u003e().AsSelf().SingleInstance();\n        }\n    }\n}\n```\n\n#### Object Resolver\n```csharp\nusing System;\nusing System.Collections.Generic;\nusing System.Linq;\nusing Autofac;\n\nnamespace bobbylite.DependencyInjection\n{\n    public class ObjectResolver\n    {\n        private readonly IComponentContext _componentContext;\n\n        public ObjectResolver(IComponentContext componentContext)\n        {\n            _componentContext = componentContext;\n        }\n\n        public T Get\u003cT\u003e()\n        {\n            return _componentContext.Resolve\u003cT\u003e();\n        }\n\n        public T Get\u003cT\u003e(params Tuple\u003cstring, object\u003e[] constructorArgs)\n        {\n            return _componentContext.Resolve\u003cT\u003e(constructorArgs.Select(arg =\u003e new NamedParameter(arg.Item1, arg.Item2)));\n        }\n\n        public IEnumerable\u003cT\u003e GetAll\u003cT\u003e()\n        {\n            return _componentContext.Resolve\u003cIEnumerable\u003cT\u003e\u003e();\n        } \n    }\n}\n```","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbobbylite%2F.netcorelibrary","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbobbylite%2F.netcorelibrary","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbobbylite%2F.netcorelibrary/lists"}