Skip to content

Commit

Permalink
revert: remove contextual binding from container
Browse files Browse the repository at this point in the history
  • Loading branch information
danieletulone committed Dec 30, 2024
1 parent 0dcaffb commit d26ec70
Show file tree
Hide file tree
Showing 3 changed files with 0 additions and 55 deletions.

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
import 'package:velvet_framework/src/core/container/contracts/velvet_container_contract.dart';
import 'package:velvet_framework/src/core/container/mixins/proxy_to_get_it_mixin.dart';

part '_contextual_binding.dart';
part '_when_context.dart';

/// The container for the Velvet framework.
/// This container is used to register and resolve dependencies.
///
Expand All @@ -13,8 +10,6 @@ class VelvetContainer extends VelvetContainerContract with ProxyToGetItMixin {
getIt.allowReassignment = true;
}

final List<ContextualBinding> _contextualBindings = [];

@override
void requireRegistrationOf<T extends Object>({String? instanceName}) {
if (isRegistered<T>(instanceName: instanceName)) {
Expand All @@ -24,11 +19,6 @@ class VelvetContainer extends VelvetContainerContract with ProxyToGetItMixin {
throw Exception('Registration of type $T is required.');
}

// Register a contextual binding
WhenContext<T> when<T>(List<Type> contexts) {
return WhenContext<T>(this, contexts);
}

@override
T get<T extends Object>({
param1,
Expand All @@ -37,32 +27,11 @@ class VelvetContainer extends VelvetContainerContract with ProxyToGetItMixin {
Type? type,
Type? context,
}) {
if (context != null) {
for (final binding in _contextualBindings) {
if (binding.contexts.contains(context) && binding.type == T) {
return binding.provider() as T;
}
}
}

return super.get<T>(
param1: param1,
param2: param2,
instanceName: instanceName,
type: type,
);
}

void _registerContextualBinding<T>(
List<Type> contexts,
T Function() provider,
) {
_contextualBindings.add(
ContextualBinding<T>(
contexts: contexts,
type: T,
provider: provider,
),
);
}
}

0 comments on commit d26ec70

Please sign in to comment.