Thursday, 30 January 2025

How to register multiple implementations of the same interface

 In a recent project, I faced an issue while registering multiple implementations of the same interface in .NET CORE. I found different solutions for multiple implementations of the same interface in .NET CORE


I faced an issue with the below. I have 3 classes with 1 interface


public interface IService { }
public class ServiceA : IService { }
public class ServiceB : IService { } 
public class ServiceC : IService { }


 In ASP.NET Core, how do I register these services and resolve them at runtime based on some key?



Solution 1: Use of Microsoft.Extensions.DependencyInjection.


Register your services as:


services.AddSingleton<IService, ServiceA>();

services.AddSingleton<IService, ServiceB>();

services.AddSingleton<IService, ServiceC>();



Then resolve with a little of Linq:


var services = serviceProvider.GetServices<IService>();

var serviceB = services.First(o => o.GetType() == typeof(ServiceB));

or


var serviceZ = services.First(o => o.Name.Equals("Z"));



Solution 2:   use of inheritance


Create a separate interface derived from the Base interface for each class.  create individual interfaces that inherit from IService, implement the inherited interfaces in your IService implementations, and register the inherited interfaces rather than the base.

In this way  we can have as many copies of the interface as we want and we can pick suitable names for each of them. And we have the benefit of type safety


public interface IService 

{

}


public interface IServiceA: IService

{}


public interface IServiceB: IService

{}


public interface IServiceC: IService

{}


public class ServiceA: IServiceA 

{}


public class ServiceB: IServiceB

{}


public class ServiceC: IServiceC

{}



Container:


container.Register<IServiceA, ServiceA>();

container.Register<IServiceB, ServiceB>();

container.Register<IServiceC, ServiceC>();




Solution 3 : Use of .NET CORE 8  Keyed DI services


Keyed DI services

Keyed dependency injection (DI) services provides a means for registering and retrieving DI services using keys. By using keys, you can scope how you register and consume services. These are some of the new APIs:


 Don’t forget to leave your feedback and comments below!

Regards

Sujeet Bhujbal

--------------------------------------------------------------------------------

Blog: www.sujeetbhujbal.com 

CodeProject:-https://www.codeproject.com/Members/SujitBhujbal

CsharpCorner:-http://www.c-sharpcorner.com/Authors/sujit9923/sujit-bhujbal.aspx

Linkedin :-http://in.linkedin.com/in/sujitbhujbal  

Medium: - https://medium.com/@SujeetBhujbal

------------------------------------------------------------------------------


Wednesday, 23 October 2024

Is Google Gemini Better Than ChatGPT? By Sujeet Bhujbal

 Introduction

         In last blog, I have written about an article Use Cases of ChatGPT in Real Life. Last Month, Google took a massive step forward for the generative AI world by releasing Gemini Ultra, the company’s most powerful chatbot ever. Gemini’s release is Google’s biggest AI move in at least a year, and Gemini is now ChatGPT’s only true competitor. 

      This article covers the key features and pricing details for  Google’s Gemini, so you will have the information you need to determine whether Gemini is better than ChatGPT for your business needs.

Is Google Gemini Better Than ChatGPT? By Sujeet Bhujbal



  1. What is Google Gemini?

Gemini is the new artificial intelligence model created by Google and its parent company, Alphabet.

Google Gemini is a family of AI models, like OpenAI's GPT. Gemini is also the name of Google's AI chatbot (formerly known as Bard).

“Gemini is the result of large-scale collaborative efforts by teams across Google, including our colleagues at Google Research,” according to Dennis Hassabis, CEO and co-founder of Google DeepMind.

The core of this AI model is to be multimodal, meaning it can easily understand data from various formats of information like:

  • Text

  • Code

  • Audio

  • Image

  • Video

   2. Google Gemini comes in three sizes.

Is Google Gemini Better Than ChatGPT? By Sujeet Bhujbal



Google Gemini is designed to run on almost any device. Google claims that its three versions—Gemini Ultra, Gemini Pro, and Gemini Nano—are capable of running efficiently on everything from data centers to smartphones. 

  • Gemini Ultra is the largest model designed for the most complex tasks. Google describes Gemini Ultra as the most capable model, which is the first one to outperform human experts on MMLU. It is completely designed for highly complex tasks and is currently in the testing phase.

  • Gemini Pro  Google Pro is an advanced reasoning, planning, and understanding version currently used to fine-tune Google Bard. This is one of Google Bard’s biggest upgrades since its launch. It's designed to be used for a variety of different tasks. Right now, a specially trained version of it is used by the Google Gemini chatbot (formerly called Bard) to handle more complex queries. In independent testing, Gemini Pro was found slightly inferior to the corresponding GPT 3.5 Turbo" model. 

  • Gemini Nano is designed to operate locally on smartphones and other mobile devices.  This model runs on smartphones, especially Google Pixel.  In theory, this would allow your smartphone to respond to simple prompts and do things like summarize text far faster than if it had to connect to an external server. 

3.How to Access Gemini AI?

            To use the Gemini web app, gemini.google.com, you’ll need to sign in with a Google Account. Gemini Apps give you direct access to Google AI.

https://gemini.google.com/app

Upgrade to Gemini Advanced

You can upgrade to Gemini Advanced, which is part of a paid plan in Google One that also includes:

With Google's 1.0 Ultra model, Gemini Advanced is far more capable at highly complex tasks like coding, logical reasoning, following nuanced instructions, and creative collaboration.

4. Use Gemini in Google Messages

You can chat with Gemini in the Google Messages app to draft messages, brainstorm ideas, plan events, or simply have a fun conversation.

What you need

  • An eligible Android phone:

    • Pixel 6 or later

    • Pixel Fold

    • Samsung Galaxy S22 or later

    • Samsung Galaxy Z Flip or Z Fold

Start a chat with Gemini in Google Messages

Important: Chats with Gemini aren’t end-to-end encrypted.

  1. On your Android phone, open Google Messages .

  2. Tap the chat with Gemini, or tap Start chat Gemini.

  3. For the first time, follow any on-screen instructions.

  4. Enter your question or prompt.

    • The first time you chat with Gemini, you can explore different conversations. Just tap a suggestion above the message field.

  5. Optionally, to add a photo to your prompt, tap Show attach media screen .

  6. Tap Send message .

5. Key Features Comparison: ChatGPT Pro vs Gemini Advanced

Gemini vs. ChatGPT: Comparison table

Notable editions and availability

Gemini Ultra, Announced for 2024

Gemini Pro, Dec. 2023

Gemini Nano, Dec. 2023

GPT-4, March 2023

GPT-3.5, Nov. 2022

Free chatbot access

Google Gemini (use to access Gemini Pro)

ChatGPT (access to GPT-3.5)

Paid chatbot access

Google One AI Premium, $19.99/month

ChatGPT Plus, $20/month (access to GPT-4 with DALL-E, browsing and analysis); ChatGPT Team, $30/month ($25/month, paid annually); ChatGPT Enterprise (contact sales)

API access

Yes, Gemini Pro.

Yes, GPT-4 Turbo, GPT-4, GPT-3.5 and others.


Visit Gemini

Visit ChatGPT

6. User Experience & Interface Comparison

Gemini allows smooth UI interactions and easy screen transitions, Gemini Advanced prioritizes user comfort and creates an natural workspace

Is Google Gemini Better Than ChatGPT? By Sujeet Bhujbal



ChatGPT Pro offers a user-friendly and minimalist UI. Beginners will appreciate its ease of use, allowing them to quickly navigate through features like content generation prompts and research summaries.

Is Google Gemini Better Than ChatGPT? By Sujeet Bhujbal



7. That’s All!

Conclusively we can say that through this innovation, Google is not just enhancing the capabilities of AI systems but is also bringing them closer to a human-like understanding of the world with AI. 

Hope you like it.



Don’t forget to leave your feedback and comments below!

Regards

Sujeet Bhujbal

https://www.sujeetbhujbal.com/

-------------------------------------------------------------------------------- 

CodeProject:-https://www.codeproject.com/Members/SujitBhujbal

CsharpCorner:-http://www.c-sharpcorner.com/Authors/sujit9923/sujit-bhujbal.aspx

Linkedin :-http://in.linkedin.com/in/sujitbhujbal  

Medium: - https://medium.com/@SujeetBhujbal

-----------------------------------------------------------------------