Open Closed

How to Inject service in static class #4033


User avatar
0
yasin.hallak.89@gmail.com created
  • ABP Framework version: v6.0.0
  • UI type: MVC
  • DB provider: EF Core
  • Tiered (MVC) or Identity Server Separated (Angular): no

Hi there ...

I need to inject service in static class. Is there any way in abp to do this please :)

Markdown supported.
Copy, paste, or drag & drop images and files (max 100 MB per file, 100 MB total per post)

5 Answer(s)
  • User Avatar
    0
    maliming created
    Support Team Fullstack Developer

    hi

    Can you share your static class?

    Markdown supported.
    Copy, paste, or drag & drop images and files (max 100 MB per file, 100 MB total per post)
  • User Avatar
    0
    yasin.hallak.89@gmail.com created

    hi

    Can you share your static class?

    public static class AssignmentExtensions
        {
            public static string AssignmentTypeHelper(this Assignment target, IStringLocalizer localize)
            {
                string assignmentType = string.Empty;
    
                if (target.IsTemporary)
                {
                    if (target.IsGuard()) assignmentType = $"{localize["Guard"]} - {localize["General.Temporary"]}";
    
                    if (target.IsReservedGuard()) assignmentType = $"{localize["ReservedGuard"]} - {localize["General.Temporary"]}";
    
                    if (target.IsFieldSupervisor())
                    {
                        assignmentType = $"{localize["FieldSupervisor"]} - {localize["General.Temporary"]}";
                    }
                }
                else
                {
                    assignmentType = $"{localize["Guard"]} - {localize["General.Permanently"]}";
                }
    
                return assignmentType;
            }
        }
    
    Markdown supported.
    Copy, paste, or drag & drop images and files (max 100 MB per file, 100 MB total per post)
  • User Avatar
    0
    maliming created
    Support Team Fullstack Developer

    You can consider passing services or IServiceProvider to static method.

    Markdown supported.
    Copy, paste, or drag & drop images and files (max 100 MB per file, 100 MB total per post)
  • User Avatar
    0
    yasin.hallak.89@gmail.com created

    You can consider passing services or IServiceProvider to static method.

    This method deep nested , I need to pass IServiceProvider to all methods !.

    I need efficient way more than this

    Markdown supported.
    Copy, paste, or drag & drop images and files (max 100 MB per file, 100 MB total per post)
  • User Avatar
    1
    gterdem created
    Senior .NET Developer

    This is not related to ABP but the language itself. Check How to inject dependency to static class.

    Markdown supported.
    Copy, paste, or drag & drop images and files (max 100 MB per file, 100 MB total per post)
Boost Your Development
ABP Live Training
Packages
See Trainings
Mastering ABP Framework Book
The Official Guide
Mastering
ABP Framework
Learn More
Mastering ABP Framework Book
Made with ❤️ on ABP v10.8.0-preview. Updated on September 09, 2026, 11:56
1
ABP Assistant
🔐 You need to be logged in to use the chatbot. Please log in first.