Comments (3)
If you have a suggestion on what would work for you to do that, please let me know. The reason it's set as internal is that I don't want to allow the user to change it "midflight" because it's not really threadsafe internally and is used in every call to build the call up, so I'd rather not lock on every field, and I can't think of a good way to make it "read-only after initial buildup".
If you'd like to take a reference to the config for testing, it can be done inside the action:
ConsulClientConfiguration myConfig = null;
using (var client = new ConsulClient((config) => { config.Datacenter = "foo"; myConfig = config; }))
{
Assert.Equals("foo", myConfig.Datacenter);
}
This may not be ideal for you but if you can write your wrapper to return a reference to the config that was supplied inside the action, that should work for testing.
from consuldotnet.
Thanks for the quick reply and workaround!
(Maybe read conclusion at end first)
My initial thought was to create an interface with all the setters removed. All the ones with getters are immutable types so this should be safe:
public interface IConsulClientConfiguration
{
/// <summary>
/// The Uri to connect to the Consul agent.
/// </summary>
Uri Address { get; }
/// <summary>
/// Datacenter to provide with each request. If not provided, the default agent datacenter is used.
/// </summary>
string Datacenter { get; }
/// <summary>
/// Token is used to provide an ACL token which overrides the agent's default token. This ACL token is used for every request by
/// clients created using this configuration.
/// </summary>
string Token { get; }
/// <summary>
/// WaitTime limits how long a Watch will block. If not provided, the agent default values will be used.
/// </summary>
TimeSpan? WaitTime { get; }
}
Then have public IConsulClientConfiguration Config { get { return _config; } }
Although this idea would allow someone to manually cast it back to ConsulClientConfiguration
and mess with it.
Exposing NetworkCredential or Certificate or other class types would be riskier because properties on them could possibly be modified.
An alternative would be to have properties on the Client which would be getters only. Which that makes the Client interface more confusing...
Conclusion So now that I explored it a little, neither of these ideas are amazing, and I'm not sure how much value it adds at all... So I'd probably vote keep it how it is :)
from consuldotnet.
Sounds good - I vote for leaving it as-is too, since you have a workaround in that you can "export" a reference from the action if you really need it, though that does leave a reference dangling outside the using, which should be OK for tests but not for "real" use.
from consuldotnet.
Related Issues (20)
- Consul.ConsulRequestException: Unexpected response, status code InternalServerError: rpc error making call: EOF HOT 4
- No way to read ServiceMeta
- ConsulConfigurationException throw if URL scheme specified in CONSUL_HTTP_ADDR environment variable. HOT 1
- Latest version is not available in Nuget HOT 2
- Add Meta dictionary to AgentService and AgentServiceRegistration HOT 1
- Does not work on netcoreapp2.1 HOT 5
- Enable HttpClientHandler pooling? HOT 2
- KV Txn call may deadlock HOT 3
- Grpc heartbeat HOT 2
- Support for Consul Connect? HOT 1
- 0.9 Port Status
- No .Net Framework 4.0 compatibility HOT 1
- Filter Service and Health by multi tags
- I hope to support the heartbeat of grpc
- Agent.ServiceRegister hangs after KV.Get with new QueryOptions {WaitIndex = index}
- Aquire Lock custom KV value
- Service status
- Bad request : Invalid wait time and multiple Get request while trying to acquire leader HOT 2
- Cluster support
- Add consul.dll.xml into the NuGet package
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from consuldotnet.