### Module Installation and Composition in Java Source: https://context7.com/unnamed/inject/llms.txt Demonstrates how to compose applications from multiple modules using Unnamed Inject. Modules define bindings and can install other modules. Dependencies are resolved by the Injector. ```java import team.unnamed.inject.AbstractModule; import team.unnamed.inject.Injector; import team.unnamed.inject.Provides; public class DatabaseModule extends AbstractModule { @Override protected void configure() { bind(ConnectionPool.class).to(HikariConnectionPool.class).singleton(); bind(TransactionManager.class).to(JpaTransactionManager.class); } @Provides public DatabaseConfig provideConfig() { return new DatabaseConfig("localhost", 3306); } } public class ServiceModule extends AbstractModule { @Override protected void configure() { bind(UserService.class).singleton(); bind(ProductService.class).singleton(); bind(OrderService.class).singleton(); } } public class ControllerModule extends AbstractModule { @Override protected void configure() { // Install other modules install(new DatabaseModule(), new ServiceModule()); // Configure controllers bind(UserController.class); bind(ProductController.class); } } // Usage Injector injector = Injector.create(new ControllerModule()); UserController controller = injector.getInstance(UserController.class); ``` -------------------------------- ### Process Dependencies using Injector in Java Source: https://github.com/unnamed/inject/blob/main/docs/basic-usage.md This example illustrates how to process declared dependencies using an Injector. It shows manual instantiation of the main class and injection of its members, demonstrating how the Injector resolves and provides dependencies like the Server. This requires an Injector class and potentially a Server class for the example to be fully functional. ```java public class Main { @Inject private Server server; public void start() { server.start(); } public static void main(String[] args) { Injector injector = Injector.create(); // here we manually tell the injector to instantiate // our Main class that declares a dependency on the // Server class, our Injector is smart and will instantiate // and set it too Main main = injector.getInstance(Main.class); main.start(); // We can alternatively do: Main main = new Main(); injector.injectMembers(main); main.start(); // however, the Injector does not know about the Main // constructor, and it will not process it so injections // there will not work. It will just inject fields and methods } } ``` -------------------------------- ### Define Database Module for Injector (Java) Source: https://github.com/unnamed/inject/blob/main/docs/config/injector-configuration.md This example demonstrates how to implement the `Module` interface to configure the Injector. The `configure` method uses a `Binder` to specify how to provide dependencies, such as binding a `Database.class` to a specific `SQLiteDependency` instance. ```java public class DatabaseModule implements Module { @Override public void configure(Binder binder) { binder.bind(Database.class) .toInstance(new SQLiteDependency("file.db")); } } ``` -------------------------------- ### Provider Injection for Lazy Initialization in Java Source: https://context7.com/unnamed/inject/llms.txt Illustrates using Provider for lazy initialization or obtaining multiple instances of a dependency. The Injector provides a Provider that can be used to get instances on demand. ```java import team.unnamed.inject.Inject; import team.unnamed.inject.Provider; import team.unnamed.inject.Injector; import team.unnamed.inject.Singleton; @Singleton public class RequestHandler { private final Provider contextProvider; @Inject public RequestHandler(Provider contextProvider) { this.contextProvider = contextProvider; } public void handleRequest() { // Get fresh instance each time (if not singleton) RequestContext context = contextProvider.get(); context.process(); } } public class RequestContext { private final String requestId; public RequestContext() { this.requestId = UUID.randomUUID().toString(); } public void process() { System.out.println("Processing request: " + requestId); } } // Usage Injector injector = Injector.create(binder -> { binder.bind(RequestContext.class); // New instance each time }); RequestHandler handler = injector.getInstance(RequestHandler.class); handler.handleRequest(); // Creates new RequestContext handler.handleRequest(); // Creates another new RequestContext ``` -------------------------------- ### Java: Class with unnamed/inject Dependency Injection Source: https://github.com/unnamed/inject/blob/main/docs/dependency-injection.md This Java example showcases dependency injection using the 'unnamed/inject' library. The '@Inject' annotation is used to declare a 'Database' dependency, simplifying the declaration compared to constructor injection. Note that this requires processing by the inject framework to function. ```java import team.unnamed.inject.Inject; public class UserDao { @Inject private Database database; } ``` -------------------------------- ### Maven Dependency for Inject Source: https://github.com/unnamed/inject/blob/main/docs/installation.md This snippet illustrates how to include the 'inject' library as a dependency in a Maven project. Replace the placeholder with the correct latest release version. ```xml team.unnamed inject %%REPLACE_latestRelease{team.unnamed:inject}%% ``` -------------------------------- ### Gradle Dependency for Inject Source: https://github.com/unnamed/inject/blob/main/docs/installation.md This snippet shows how to add the 'inject' library as a dependency in a Gradle project. Ensure you replace the placeholder with the actual latest release version. ```kotlin dependencies { implementation("team.unnamed:inject:%%REPLACE_latestRelease{team.unnamed:inject}%%") } ``` -------------------------------- ### Create Injector with Modules (Java) Source: https://github.com/unnamed/inject/blob/main/docs/config/injector-configuration.md This code snippet shows how to create an instance of the Injector by passing in various Module implementations. Modules are used to configure the Injector's behavior and dependencies. ```java Injector injector = Injector.create( new DatabaseModule(), new WebServerModule() ); // ... ``` -------------------------------- ### Create Injector with Lambda Module Configuration - Java Source: https://context7.com/unnamed/inject/llms.txt Demonstrates basic injector creation using a lambda expression for module configuration and binding a specific instance. Also shows how to create an injector with multiple modules and retrieve an instance from it. ```java import team.unnamed.inject.Injector; // Simple injector with inline module Injector injector = Injector.create(binder -> { binder.bind(DatabaseConnection.class).toInstance(new DatabaseConnection("localhost")); }); // Multi-module injector Injector injector = Injector.create( new DatabaseModule(), new ServiceModule(), new ControllerModule() ); // Get instance from injector UserService service = injector.getInstance(UserService.class); ``` -------------------------------- ### Binding Strings with Annotation Instance Qualifiers Source: https://github.com/unnamed/inject/blob/main/docs/config/advanced-keys.md Shows how to bind String types to instances using a custom qualifier annotation 'Index' with a parameter. This method is useful for creating unique qualifiers based on dynamic values. ```java // here we create the qualifier annotation @Qualifier @interface Index { int value(); } // bind objects using it public class MyModule implements Module { @Override public void configure(Binder binder) { binder.bind(String.class).qualified(newIndex(0)).toInstance("0"); binder.bind(String.class).qualified(newIndex(1)).toInstance("1"); } private Index newIndex(int value) { return new Index() { @Override public Class annotationType() { return Index.class; } @Override public int value() { return value; } }; } } // and finally use it public class MyClass { @Inject @Index(0) private String zero; @Inject @Index(1) private String one; } ``` -------------------------------- ### Binding Integers with Custom Qualifier Annotation Source: https://github.com/unnamed/inject/blob/main/docs/config/advanced-keys.md Demonstrates binding integer types to specific instances using a custom qualifier annotation 'Two'. This allows for distinct injection of the same type with different values based on the annotation. ```java public class MyModule implements Module { @Override public void configure(Binder binder) { binder.bind(int.class).toInstance(1); binder.bind(int.class).markedWith(Two.class).toInstance(2); } } public class MyClass { @Inject @Two private int two; // value = 2 @Inject private int one; // value = 1 } ``` -------------------------------- ### Add Inject Dependency to Maven Project Source: https://github.com/unnamed/inject/wiki/Home This snippet demonstrates how to integrate the unnamed/inject library into your project using Maven. It involves setting up the repository and defining the dependency in your pom.xml file. ```xml unnamed-public https://repo.unnamed.team/repository/unnamed-public/ team.unnamed inject 1.0.0 ``` -------------------------------- ### Binding Interfaces to Implementations - Java Source: https://context7.com/unnamed/inject/llms.txt Demonstrates how to bind interfaces to their concrete implementations using the binding DSL. This allows for polymorphism and easy swapping of implementations. It also shows binding to a provider method. ```java import team.unnamed.inject.Injector; public interface PaymentProcessor { void process(Payment payment); } public class CreditCardProcessor implements PaymentProcessor { public void process(Payment payment) { // Process credit card payment } } public class PayPalProcessor implements PaymentProcessor { public void process(Payment payment) { // Process PayPal payment } } // Binding configuration Injector injector = Injector.create(binder -> { // Bind interface to implementation binder.bind(PaymentProcessor.class).to(CreditCardProcessor.class); // Alternative: bind to provider binder.bind(PaymentProcessor.class).toProvider(() -> new CreditCardProcessor()); }); PaymentProcessor processor = injector.getInstance(PaymentProcessor.class); // Returns instance of CreditCardProcessor ``` -------------------------------- ### Constructor Injection for Dependencies - Java Source: https://context7.com/unnamed/inject/llms.txt Illustrates automatic dependency injection into constructors annotated with @Inject. Shows how to define services that depend on repositories, which in turn depend on other services, and how the Injector resolves these dependencies. ```java import team.unnamed.inject.Inject; import team.unnamed.inject.Injector; public class UserRepository { private final DatabaseConnection connection; @Inject public UserRepository(DatabaseConnection connection) { this.connection = connection; } } public class UserService { private final UserRepository repository; @Inject public UserService(UserRepository repository) { this.repository = repository; } } // Usage Injector injector = Injector.create(binder -> { binder.bind(DatabaseConnection.class).toInstance(new DatabaseConnection("localhost")); }); UserService service = injector.getInstance(UserService.class); // UserService is created with UserRepository injected // UserRepository is created with DatabaseConnection injected ``` -------------------------------- ### Add Inject Dependency to Gradle Project Source: https://github.com/unnamed/inject/wiki/Home This snippet shows how to add the unnamed/inject library as a dependency to your project using Gradle. It includes configuring the repository and declaring the implementation dependency. ```kotlin repositories { maven("https://repo.unnamed.team/repository/unnamed-public/") } dependencies { implementation("team.unnamed:inject:1.0.0") } ``` -------------------------------- ### Singleton Scope Convenience Binding in Java Source: https://github.com/unnamed/inject/blob/main/docs/config/scopes.md This snippet shows a more concise way to bind an interface to an implementation with singleton scope using the '.singleton()' convenience method. ```java binder.bind(Database.class).to(MySQLDatabase.class).singleton(); ``` -------------------------------- ### Binding with @Named Annotation Source: https://github.com/unnamed/inject/blob/main/docs/config/advanced-keys.md Illustrates the usage of the built-in @Named annotation for binding and injecting objects. This is a common practice for distinguishing between multiple instances of the same type. ```java binder.bind(Foo.class).named("name").toInstance(new Foo("Hello!")); @Inject @Named("name") private Foo foo; ``` -------------------------------- ### Binding Generic Types with TypeReference Source: https://github.com/unnamed/inject/blob/main/docs/config/advanced-keys.md Demonstrates how to bind generic types, such as List, using the TypeReference class. This is necessary when the type itself contains generic parameters. ```java public class MyGenericsModule implements Module { @Override public void configure(Binder binder) { // note the {} at the end, they are there because we must // instantiate a TypeReference subclass in order to obtain // the generic type in the parameter binder.bind(new TypeReference>() {}) .toInstance(Arrays.asList("Hello", "World")); } } public class MyClass { @Inject private List words; } ``` -------------------------------- ### Singleton Scope Binding in Java Source: https://github.com/unnamed/inject/blob/main/docs/config/scopes.md This snippet demonstrates how to bind an interface to an implementation and specify the singleton scope for the binding using the 'in' method with Scopes.SINGLETON. ```java binder.bind(Database.class).to(MySQLDatabase.class).in(Scopes.SINGLETON); ``` -------------------------------- ### Java: Class with Constructor Dependency Injection Source: https://github.com/unnamed/inject/blob/main/docs/dependency-injection.md This Java code illustrates a 'UserDao' class using constructor dependency injection. The 'Database' dependency is passed as an argument to the constructor, allowing for easy replacement with different implementations, enhancing testability and reusability. ```java public class UserDao { private final Database database; public UserDao(Database database) { this.database = database; } // ... } ``` -------------------------------- ### Provider Methods in Java Source: https://context7.com/unnamed/inject/llms.txt Define provider methods within modules using the @Provides annotation for complex object creation. These methods can have dependencies injected automatically by the injector. This allows for flexible and controlled instantiation of objects, including singleton instances. ```java import team.unnamed.inject.Inject; import team.unnamed.inject.Provides; import team.unnamed.inject.Singleton; import team.unnamed.inject.Named; import team.unnamed.inject.AbstractModule; import team.unnamed.inject.Injector; import java.util.UUID; public class ApplicationModule extends AbstractModule { @Override protected void configure() { bind(UserRepository.class).to(MySQLUserRepository.class).singleton(); } @Provides public DatabaseConfig provideConfig() { return new DatabaseConfig("localhost", 3306, "myapp"); } @Provides @Singleton public ConnectionPool provideConnectionPool(DatabaseConfig config) { // Dependencies are automatically injected return new HikariConnectionPool(config); } @Provides @Named("sessionId") public String provideSessionId() { return UUID.randomUUID().toString(); } @Provides @Named("apiKey") public String provideApiKey(DatabaseConfig config) { return config.loadApiKey(); } } public class Application { @Inject private ConnectionPool pool; @Inject @Named("sessionId") private String sessionId; } // Usage Injector injector = Injector.create(new ApplicationModule()); Application app = injector.getInstance(Application.class); ``` -------------------------------- ### Bind with @Targetted Annotation in Java Source: https://github.com/unnamed/inject/blob/main/docs/config/binding-annotations.md This snippet demonstrates how to use the @Targetted annotation to bind an interface to a specific implementation class, such as binding the Database interface to MySQLDatabase. This is an alternative to the .to(...) method in the Binder DSL. ```java @Targetted(MySQLDatabase.class) public interface Database { // ... } ``` -------------------------------- ### Assisted Injection with Factories (Java) Source: https://context7.com/unnamed/inject/llms.txt Implement assisted injection to create factories for objects that require both framework-injected dependencies and runtime-provided parameters. Define a factory interface extending ValueFactory and bind it using toFactory. The framework automatically generates the implementation. ```java import team.unnamed.inject.Inject; import team.unnamed.inject.Injector; import team.unnamed.inject.assisted.Assist; import team.unnamed.inject.assisted.Assisted; import team.unnamed.inject.assisted.ValueFactory; public class PaymentTransaction { private final String transactionId; private final double amount; private final PaymentGateway gateway; // Injected private final Logger logger; // Injected @Assisted public PaymentTransaction( @Assist String transactionId, // Provided at creation time @Assist double amount, // Provided at creation time PaymentGateway gateway, // Injected by framework Logger logger // Injected by framework ) { this.transactionId = transactionId; this.amount = amount; this.gateway = gateway; this.logger = logger; } public void process() { logger.log("Processing transaction: " + transactionId); gateway.charge(amount); } } // Factory interface (implementation generated automatically) public interface PaymentTransactionFactory extends ValueFactory { PaymentTransaction create(String transactionId, double amount); } // Configuration Injector injector = Injector.create(binder -> { binder.bind(PaymentTransaction.class).toFactory(PaymentTransactionFactory.class); binder.bind(PaymentGateway.class).to(StripeGateway.class); binder.bind(Logger.class).toInstance(new ConsoleLogger()); }); // Usage PaymentTransactionFactory factory = injector.getInstance(PaymentTransactionFactory.class); PaymentTransaction tx1 = factory.create("TXN-001", 99.99); PaymentTransaction tx2 = factory.create("TXN-002", 149.50); tx1.process(); tx2.process(); ``` -------------------------------- ### Direct Binding in Java Source: https://github.com/unnamed/inject/blob/main/docs/config/bindings.md Demonstrates a direct binding where a type (Database.class) is linked to a provider function. This function is invoked by the injector whenever an instance of Database is requested. No external dependencies are explicitly mentioned for this snippet. ```java binder.bind(Database.class).toProvider(() -> { System.out.println("Database requested!"); return new SQLiteDependency("file.db"); }); ``` -------------------------------- ### Linked Binding in Java Source: https://github.com/unnamed/inject/blob/main/docs/config/bindings.md Illustrates a linked binding, associating an abstract type (Database.class) with a concrete sub-type (MySQLDatabase.class). The injector will attempt to instantiate and provide an instance of MySQLDatabase when Database is requested. This implies that MySQLDatabase must be instantiable. ```java binder.bind(Database.class).to(MySQLDatabase.class); ``` -------------------------------- ### Singleton Scope via Annotation in Java Source: https://github.com/unnamed/inject/blob/main/docs/config/scopes.md This snippet illustrates how to define a class as a singleton using the '@Singleton' annotation, which is then used for dependency injection. ```java @Singleton public class MySQLDatabase implements Database { } ``` -------------------------------- ### Java: Class without Dependency Injection Source: https://github.com/unnamed/inject/blob/main/docs/dependency-injection.md This Java code demonstrates a class 'UserDao' that directly creates its 'Database' dependency. This approach makes it difficult to test or reuse the class with different database implementations or configurations. ```java public class UserDao { private final Database database = new SQLiteDatabase("/myfile.dat"); // ... } ``` -------------------------------- ### Static Member Injection in Java Source: https://context7.com/unnamed/inject/llms.txt Shows how to inject dependencies into static fields and methods using Unnamed Inject. The Injector can be used to inject static members after configuration. ```java import team.unnamed.inject.Inject; import team.unnamed.inject.Injector; public class GlobalConfiguration { @Inject private static Logger logger; @Inject private static DatabaseConfig databaseConfig; public static void initialize() { logger.log("Initializing with config: " + databaseConfig); } } // Usage Injector injector = Injector.create(binder -> { binder.bind(Logger.class).toInstance(new ConsoleLogger()); binder.bind(DatabaseConfig.class).toInstance(new DatabaseConfig("prod.db")); }); injector.injectStaticMembers(GlobalConfiguration.class); GlobalConfiguration.initialize(); ``` -------------------------------- ### Field and Method Injection After Construction - Java Source: https://context7.com/unnamed/inject/llms.txt Shows how to inject dependencies into fields and methods after an object has been constructed, using the @Inject annotation. This is useful for setting up dependencies that are not part of the constructor. ```java import team.unnamed.inject.Inject; import team.unnamed.inject.Injector; public class OrderProcessor { @Inject private PaymentGateway paymentGateway; @Inject private NotificationService notificationService; private Logger logger; @Inject public void setLogger(Logger logger) { this.logger = logger; } public void processOrder(Order order) { paymentGateway.charge(order); notificationService.notify(order.getCustomer()); logger.log("Order processed: " + order.getId()); } } // Usage Injector injector = Injector.create(binder -> { binder.bind(PaymentGateway.class).toInstance(new StripeGateway()); binder.bind(NotificationService.class).to(EmailNotificationService.class); binder.bind(Logger.class).to(FileLogger.class); }); OrderProcessor processor = injector.getInstance(OrderProcessor.class); ``` -------------------------------- ### Bind with @ProvidedBy Annotation in Java Source: https://github.com/unnamed/inject/blob/main/docs/config/binding-annotations.md This snippet shows how to use the @ProvidedBy annotation to bind an interface to a Provider class, such as binding the Database interface to DatabaseProvider. This is an alternative to the .toProvider(...) method in the Binder DSL. ```java @ProvidedBy(DatabaseProvider.class) public interface Database { } class DatabaseProvider implements Provider { @Override public Database get() { // ... } } ``` -------------------------------- ### Instance Binding in Java Source: https://github.com/unnamed/inject/blob/main/docs/config/bindings.md Shows an instance binding, where a type (Database.class) is directly associated with a pre-existing instance (new SQLiteDatabase("file.db")). The injector will consistently return this exact instance whenever the type is requested, ensuring immutability or shared state. ```java binder.bind(Database.class).toInstance(new SQLiteDatabase("file.db")); ``` -------------------------------- ### Named Qualifiers in Java Source: https://context7.com/unnamed/inject/llms.txt Allows distinguishing between multiple bindings of the same type using the @Named annotation. This is useful when you need different implementations or configurations for the same interface. Dependencies with specific names can be injected using @Inject and @Named. ```java import team.unnamed.inject.Inject; import team.unnamed.inject.Named; import team.unnamed.inject.Injector; import team.unnamed.inject.AbstractModule; public class PaymentModule extends AbstractModule { @Override protected void configure() { bind(PaymentProcessor.class) .named("creditCard") .to(CreditCardProcessor.class); bind(PaymentProcessor.class) .named("paypal") .to(PayPalProcessor.class); } } public class CheckoutService { private final PaymentProcessor creditCardProcessor; private final PaymentProcessor paypalProcessor; @Inject public CheckoutService( @Named("creditCard") PaymentProcessor creditCardProcessor, @Named("paypal") PaymentProcessor paypalProcessor ) { this.creditCardProcessor = creditCardProcessor; this.paypalProcessor = paypalProcessor; } } // Usage Injector injector = Injector.create(new PaymentModule()); CheckoutService service = injector.getInstance(CheckoutService.class); ``` -------------------------------- ### Declare Dependencies with @Inject in Java Source: https://github.com/unnamed/inject/blob/main/docs/basic-usage.md This snippet shows how to declare dependencies using the @Inject annotation in a Java class field. These fields represent dependencies that the system needs to provide. No external libraries are explicitly mentioned as required for this basic declaration. ```java public class ItemDao { @Inject private Database database; @Inject private Configuration configuration; // ... } ``` -------------------------------- ### Multi-Bindings for Collections and Maps (Java) Source: https://context7.com/unnamed/inject/llms.txt Configure Unnamed Inject to bind multiple instances or types to collections like Lists and Sets, or to Maps with specified key types. This allows for flexible dependency injection of multiple related objects. Ensure correct types are used for keys in map bindings. ```java import team.unnamed.inject.Inject; import team.unnamed.inject.Named; import team.unnamed.inject.Injector; import java.util.List; import java.util.Map; // Multi-binding configuration Injector injector = Injector.create(binder -> { // Bind multiple strings to a list binder.multibind(String.class) .asList() .toInstance("admin@example.com") .toInstance("support@example.com"); // Bind multiple plugins binder.multibind(Plugin.class) .asList() .to(LoggingPlugin.class) .to(AuthenticationPlugin.class) .to(CachePlugin.class); // Bind map with string keys binder.multibind(DatabaseConfig.class) .asMap(String.class) .bind("primary").toInstance(new DatabaseConfig("db1.example.com")) .bind("replica").toInstance(new DatabaseConfig("db2.example.com")); // Named multi-binding binder.multibind(String.class) .named("adminEmails") .asList() .toInstance("admin1@example.com") .toInstance("admin2@example.com"); }); public class NotificationService { @Inject private List emailRecipients; // Contains all bound strings @Inject private List plugins; // Contains all plugin instances @Inject private Map databases; // Map with "primary" and "replica" keys @Inject @Named("adminEmails") private List adminEmails; public void sendNotifications() { emailRecipients.forEach(email -> sendEmail(email, "Notification")); } } NotificationService service = injector.getInstance(NotificationService.class); ``` -------------------------------- ### Singleton Scope in Java Source: https://context7.com/unnamed/inject/llms.txt Ensures that only one instance of a class is created and reused throughout the application's lifecycle. This is achieved by annotating the class with @Singleton or by configuring the binding as singleton within a module. Dependencies are managed automatically by the injector. ```java import team.unnamed.inject.Inject; import team.unnamed.inject.Singleton; import team.unnamed.inject.Injector; import team.unnamed.inject.AbstractModule; @Singleton public class DatabaseConnection { private final String url; public DatabaseConnection() { this.url = "jdbc:mysql://localhost:3306/mydb"; } } // Or configure via module public class DatabaseModule extends AbstractModule { @Override protected void configure() { bind(ConnectionPool.class).to(HikariConnectionPool.class).singleton(); bind(CacheManager.class).toInstance(new CacheManager()); // Always singleton } } // Usage Injector injector = Injector.create(new DatabaseModule()); ConnectionPool pool1 = injector.getInstance(ConnectionPool.class); ConnectionPool pool2 = injector.getInstance(ConnectionPool.class); // pool1 == pool2 (same instance) ``` -------------------------------- ### Generic Type Binding with TypeReference (Java) Source: https://context7.com/unnamed/inject/llms.txt Configure bindings for generic types using TypeReference to ensure type safety at compile time. This is crucial when injecting generic interfaces or classes. The TypeReference class allows for precise specification of generic type arguments. ```java import team.unnamed.inject.Inject; import team.unnamed.inject.Injector; import team.unnamed.inject.key.TypeReference; import java.util.List; public interface Repository { T findById(long id); List findAll(); } public class UserRepository implements Repository { public User findById(long id) { /* ... */ } public List findAll() { /* ... */ } } public class ProductRepository implements Repository { public Product findById(long id) { /* ... */ } public List findAll() { /* ... */ } } // Configuration with generic types Injector injector = Injector.create(binder -> { binder.bind(new TypeReference>() {}) // Use anonymous inner class for TypeReference .to(new TypeReference() {}); binder.bind(new TypeReference>() {}) .to(new TypeReference() {}); }); // Usage Repository userRepo = injector.getInstance(new TypeReference>() {}); Repository productRepo = injector.getInstance(new TypeReference>() {}); User user = userRepo.findById(1L); Product product = productRepo.findById(100L); ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.