Replies: 1 comment
-
Probably your best bet is do to something like a factory. You could have some helper class like the following: public class BluetoothController
{
public Type? ServiceType { get; set; }
} Then in your registrations you could do something like: container.RegisterSingleton<BluetoothController>();
container.Register<IBluetoothService>(c => {
var controller = c.Resolve<BluetoothController>();
// You may want to just throw an exception if there is no set type
var type = controller.Type ?? typeof(EmptyBluetoothDevice);
return (IBluetoothService)c.Resolve(type);
}); In your code you can simply set the type for which instance you want on the Controller and then the next time you resolve you'll get the one you want. |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I have a service class for each typeof bluetooth device something like
Deviceonebluetoothservice
Devicetwobluetoothservice
when I change the device to connect it has to unregister from the Deviceonebluetoothservice and register the Devicetwobluetoothservice but presently it is registering both the services because of which both services are getting called and Bluetooth connection is to happening
Beta Was this translation helpful? Give feedback.
All reactions