{"id":24517842,"url":"https://github.com/moattarwork/foil","last_synced_at":"2025-07-20T08:38:27.052Z","repository":{"id":25156232,"uuid":"102525435","full_name":"moattarwork/foil","owner":"moattarwork","description":"Extensions to allow interception for IServiceCollection in .Net standard and core","archived":false,"fork":false,"pushed_at":"2022-12-08T09:00:39.000Z","size":32,"stargazers_count":14,"open_issues_count":8,"forks_count":4,"subscribers_count":5,"default_branch":"master","last_synced_at":"2025-03-27T23:03:21.774Z","etag":null,"topics":["aspnet-core","aspnetcore","castle-core","csharp","dependency-injection","dotnet-core","dotnet-standard","inteceptor"],"latest_commit_sha":null,"homepage":"","language":"C#","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/moattarwork.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2017-09-05T20:12:53.000Z","updated_at":"2022-12-06T18:09:45.000Z","dependencies_parsed_at":"2023-01-14T02:13:54.986Z","dependency_job_id":null,"html_url":"https://github.com/moattarwork/foil","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/moattarwork%2Ffoil","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/moattarwork%2Ffoil/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/moattarwork%2Ffoil/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/moattarwork%2Ffoil/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/moattarwork","download_url":"https://codeload.github.com/moattarwork/foil/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248856047,"owners_count":21172683,"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":["aspnet-core","aspnetcore","castle-core","csharp","dependency-injection","dotnet-core","dotnet-standard","inteceptor"],"created_at":"2025-01-22T01:35:33.538Z","updated_at":"2025-04-14T09:42:48.731Z","avatar_url":"https://github.com/moattarwork.png","language":"C#","funding_links":[],"categories":[],"sub_categories":[],"readme":"# foil\n\n[![Build status](https://ci.appveyor.com/api/projects/status/x97rqf3f82647e1j?svg=true)](https://ci.appveyor.com/project/moattarwork/foil-nha98)\n[![NuGet Status](https://img.shields.io/nuget/v/Foil.svg)](https://www.nuget.org/packages/Foil/)\n\nfoil is a set of extensions which enable interception support for .Net Core dependency injection framework. It uses Castle Core framework to enable on the fly proxy creation of container elements.\n\nThe package can be downloaded from NuGet using\n\n```\ninstall-package Foil\ninstall-package Foil.Logging\n```\n\nor \n\n```\ndotnet add package Foil\ndotnet add package Foil.Logging\n```\n\n\n## Usage\nThe package consists of extensions to register services as Transient, Scoped or Singleton with the interceptors.\n\n```\nservices.AddTransientWithInterception\u003cISampleService, SampleService\u003e(m =\u003e m.InterceptBy\u003cLogInterceptor\u003e()\n    .UseMethodConvention\u003cNonQueryMethodsConvention\u003e());\n```  \nor\n```\nservices.AddSingletonWithInterception\u003cISampleService, SampleService\u003e(m =\u003e m.InterceptBy\u003cLogInterceptor\u003e()\n    .UseMethodConvention\u003cNonQueryMethodsConvention\u003e());\n\n```\nConvention give this option to specify which methods need to be selected for interception. The are couple of predefined convention which can be used:\n- AllMethodsConvention (Default)\n- NonQueryMethodsConvention\n\nCustom conventions can be provided by implementing IMethodConvention.\n\n## Code sample\n\n    class Program\n    {\n        static void Main(string[] args)\n        {\n            var services = new ServiceCollection();\n\n            services.AddTransientWithInterception\u003cISampleService, SampleService\u003e(m =\u003e m.InterceptBy\u003cLogInterceptor\u003e());\n\n            var provider = services.BuildServiceProvider();\n\n            var service = provider.GetRequiredService\u003cISampleService\u003e();\n            service.Call();\n        }\n    }\n    \n    public interface ISampleService\n    {\n        void Call();\n        string State { get; }\n    }\n    \n    public class SampleService : ISampleService\n    {\n        public string State { get; private set; } = string.Empty;\n        \n        public virtual void Call()\n        {\n            State = \"Changed\";\n            Console.WriteLine(\"Hello Sample\");\n        }\n    }\n\n    public class LogInterceptor : IInterceptor\n    {\n        private readonly ISampleLogger _logger;\n\n        public LogInterceptor(ISampleLogger logger)\n        {\n            _logger = logger;\n        }\n\n        public virtual void Intercept(IInvocation invocation)\n        {\n            _logger.Log(\"Before invocation\");\n            \n            invocation.Proceed();\n            \n            _logger.Log(\"After invocation\");\n        }\n    }\n    \n    \n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmoattarwork%2Ffoil","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmoattarwork%2Ffoil","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmoattarwork%2Ffoil/lists"}