v3 Audio Unit Extensions: how to set sample rate and number of channels

I'm developing a v3 Audio Unit Extension and I'd like it to be able to work on both mono and stereo files with a range of sample rates. All of the examples that I've come across have the sample rate and number of channels hard-coded within a standard init method of one of the audio unit's classes. It doesn't seem like there is a way to pass this information from a host to the audio unit when it is being set up. Ideally, I'd like to have access to it within the audio unit's initWithComponentDescription method, as that's where I set up the kernel. I managed to get it working in my host app, but did so by calling setters on the audio unit that other hosts don't know about. I'd like my extensions to load and function in other hosts as well. How are sample rate and number of channels supposed to be handled?
I spent another day on this. There are various ways that I can get it to work within my own host app, but the documentation (Incorporating Audio Effects and Instruments) says that I should instantiate the audio unit using AVAudioUnit's instantiateWithComponentDescription: options: completionHandler:. This is also what the AUv3Filter sample code seems to be doing. The componentDescription is all that gets passed to the Audio Unit when it gets initialized, and that doesn't provide the number of channels. NumChannels is needed when initializing the busses in the audio unit. As I said in the original post, the number of channels is hard-coded as 2 in the AUv3Filter sample code, and all other examples that I've been able to find. Indeed, the the AUv3Filter audio unit doesn't work with mono files, at least not within my host. If I change the 2 to 1 it then works with mono files, but not stereo. This is the issue I'm trying to resolve. What am I missing?

btw, I'd also like to know the sample rate inside of the audio unit, for dsp calculations. I'm able to get that with lower-level core audio calls to the hardware, but that doesn't feel like the right solution.
I should have mentioned, I'm developing for MacOS, using Xcode 12 and running Catalina.

One more thing... I'm instantiating the audio units when the user selects a menu item. there is no audio playing and no AVAudioEngine set up. Then I'm creating the AVAudioEngine and adding the audio unit when a play button is pressed. I don't see why that matters, but perhaps it may shed light on something I'm doing wrong.
Ok, I solved this issue by setting the format of the audio unit's input and output busses from the host when it prepares to play the sound. In other words, the hard-coded format that gets set within the audio unit upon initialization is not really the format used. Each time a sound is to be played, the format is set on the audio unit busses before the audio engine starts. I guess this makes sense because the format could change after the AU has been instantiated. I'd still appreciate confirmation that this is the correct approach.
v3 Audio Unit Extensions: how to set sample rate and number of channels
 
 
Q