title: Problem with Dependency Injection and Get It in Flutter
body: <p>I have been learning about Dependency Injection and now I have implemented an example in dart. But I'm facing an issue with get_it package. Here's the code:</p>
  <p>'MessageService.dart'</p>
  <pre><code>abstract class MessageService {
    void sendMessage(String msg, String rec);
  }
  
  class EmailServiceImpl implements MessageService {
    @override
    void sendMessage(String message, String receiver) {
      //logic to send email
      print(&quot;Email sent to $receiver with message $message.&quot;);
    }
  }
  
  class SMSServiceImpl implements MessageService {
    @override
    void sendMessage(String message, String receiver) {
      //logic to send SMS
      print(&quot;SMS sent to $receiver with message $message.&quot;);
    }
  }
    
  </code></pre>
  <p>'injection_container.dart'</p>
  <pre><code>import 'package:get_it/get_it.dart';
  
  import 'MessageService.dart';
  import 'main.dart';
  
  final getIt = GetIt.instance;
  
  void init() async {
    getIt.registerFactory&lt;Client&gt;(() =&gt; Client());
    getIt.registerFactory&lt;MyApplication&gt;(() =&gt; MyApplication(EmailServiceImpl()));
    getIt.registerFactory&lt;MessageService&gt;(() =&gt; EmailServiceImpl());
    getIt.registerFactory&lt;MessageService&gt;(() =&gt; SMSServiceImpl());
  }
  </code></pre>
  <p>'main.dart'</p>
  <pre><code>import 'MessageService.dart';
  import 'injection_container.dart' as di;
  
  void main() {
    di.init();
    di.getIt&lt;Client&gt;().send();
  }
  
  class MyApplication {
    MessageService _service;
  
    MyApplication(this._service);
  
    void processMessages(String msg, String rec) {
      //do some msg validation, manipulation logic etc
      this._service.sendMessage(msg, rec);
    }
  }
  
  class Client {
    void send() {
      MyApplication app = di.getIt&lt;MyApplication&gt;();
      app.processMessages(&quot;Hi Bill&quot;, &quot;bill@abc.com&quot;);
    }
  }
  </code></pre>
  <p>But when registering both EmailServiceImpl and SMSServiceImpl in injection_container.dart it gives me in error as : Unhandled Exception: Invalid argument(s): Object/factory with  type MessageService is already registered inside GetIt.</p>
  <p>If I comment out SMSServiceImpl registration it works fine. Can someone tell what's the problem?
  And it would be helpful if someone can review my Dependency Injection example. Is it the right way to present Dependency Injection?</p>