3
Answers

Service object initialization approach/ Static

Sanjay Sharma

Sanjay Sharma

7y
579
1
Hi,
 
I am using IBusinessService class. I use one helper method to create instance of this class.
 
creating instancce of this class is Expensive and takes time. I want to avoid create instance when IBusinessService already initaizalize.
 
class A
{
    private readonly IBusinessService _service = API.BusinessService(); 
    
   method1();
   method2(); 
    
In above _service always created.
 
Using static suffices but observed break sometimes. application is api based so static is not recommanded I guess. 
Answers (3)