Search Results

Search found 581 results on 24 pages for 'ioc'.

Page 10/24 | < Previous Page | 6 7 8 9 10 11 12 13 14 15 16 17  | Next Page >

  • Structure map and generics (in XML config)

    - by James D
    Hi I'm using the latest StructureMap (2.5.4.264), and I need to define some instances in the xml configuration for StructureMap using generics. However I get the following 103 error: Unhandled Exception: StructureMap.Exceptions.StructureMapConfigurationException: StructureMap configuration failures: Error: 103 Source: Requested PluginType MyTest.ITest`1[[MyTest.Test,MyTest]] configured in Xml cannot be found Could not create a Type for 'MyTest.ITest`1[[MyTest.Test,MyTest]]' System.ApplicationException: Could not create a Type for 'MyTest.ITest`1[[MyTest.Test,MyTest]]' ---> System.TypeLoadException: Could not loa d type 'MyTest.ITest`1' from assembly 'StructureMap, Version=2.5.4.264, Culture=neutral, PublicKeyToken=e60ad81abae3c223'. at System.RuntimeTypeHandle._GetTypeByName(String name, Boolean throwOnError, Boolean ignoreCase, Boolean reflectionOnly, StackCrawlMark& stackMark, Boolean loadTypeFromPartialName) at System.RuntimeTypeHandle.GetTypeByName(String name, Boolean throwOnError, Boolean ignoreCase, Boolean reflectionOnly, StackCrawlMark& stackMark) at System.RuntimeType.PrivateGetType(String typeName, Boolean throwOnError, Boolean ignoreCase, Boolean reflectionOnly, StackCrawlMark& s tackMark) at System.Type.GetType(String typeName, Boolean throwOnError) at StructureMap.Graph.TypePath.FindType() --- End of inner exception stack trace --- at StructureMap.Graph.TypePath.FindType() at StructureMap.Configuration.GraphBuilder.ConfigureFamily(TypePath pluginTypePath, Action`1 action) A simply replication of the code is as follows: public interface ITest<T> { } public class Test { } public class Concrete : ITest<Test> { } Which I then wish to define in the XML configuration something as follows: <DefaultInstance PluginType="MyTest.ITest`1[[MyTest.Test,MyTest]],MyTest" PluggedType="MyTest.Concrete,MyTest" Scope="Singleton" /> I've been racking my brain, however I can't see what I'm doing wrong - I've used Type.GetType to verify the type actually is valid which it is. Anyone have any ideas? Thanks !

    Read the article

  • Why can't I inject value null with Ninjects ConstructorArgument?

    - by stiank81
    When using Ninjects ConstructorArgument you can specify the exact value to inject to specific parameters. Why can't this value be null, or how can I make it work? Maybe it's not something you'd like to do, but I want to use it in my unit tests.. Example: public class Ninja { private readonly IWeapon _weapon; public Ninja(IWeapon weapon) { _weapon = weapon; } } public void SomeFunction() { var kernel = new StandardKernel(); var ninja = kernel.Get<Ninja>(new ConstructorArgument("weapon", null)); }

    Read the article

  • Using StructureMap, when a default concrete type is defined in one registry, can it be redefined in

    - by Mark Rogers
    In the project I'm working on I have a StructureMap registry for the main web project and another registry for my integration tests. During some of the tests I wire up the web project's registry, so that I can get objects out of the container for testing. In one case I want to be able to replace a default concrete type from the web registry with one in the test registry. Is this possible? How do you do it?

    Read the article

  • When using Dependency Injection with StructureMap how do I chooose among multiple constructors?

    - by Mark Rogers
    I'm trying to get structuremap to build Fluent Nhibernate's SessionSource object for some of my intregration tests. The only problem is that Fluent's concrete implementation of ISessionSource (SessionSource) has 3 constructors: public SessionSource(PersistenceModel model) { Initialize(new Configuration().Configure(), model); } public SessionSource(IDictionary<string, string> properties, PersistenceModel model) { Initialize(new Configuration().AddProperties(properties), model); } public SessionSource(FluentConfiguration config) { configuration = config.Configuration; sessionFactory = config.BuildSessionFactory(); dialect = Dialect.GetDialect(configuration.Properties); } I've tried configuring my ObjectFactory supplying an argument for the first constructor but it seems like it wants to try the second one. How do I configure my ObjectFactory so that I can choose the first constructor or perhaps even another one if I decide to use that?

    Read the article

  • Can StructureMap be configured so that one can use different .config settings based on whether the p

    - by Mark Rogers
    I know that in StructureMap I can read from my *.config files (or files referenced by them), when I want to pass specific arguments to an object's constructor. ForRequestedType<IConfiguration>() .TheDefault.Is.OfConcreteType<SqlServerConfiguration>() .WithCtorArg("db_server_address") .EqualToAppSetting("data.db_server_address") But what I would like to do is read from one config setting in debug mode and another in release mode. Sure I could surround the .EqualToAppSetting("data.db_server_address"), with #if DEBUG, but for some reason those statements make me cringe a little when I put them in. I'd like to know if there was some way to do this with the StructureMap library itself. So can I feed my objects different settings based on whether the project is built in debug or release mode?

    Read the article

  • Bad Design? Constructor of composition uses `this`

    - by tanascius
    Example: class MyClass { Composition m_Composition; void MyClass() { m_Composition = new Composition( this ); } } I am interested in using depenency-injection here. So I will have to refactor the constructor to something like: void MyClass( Composition composition ) { m_Composition = composition; } However I get a problem now, since the Composition-object relies on the object of type MyClass which is just created. Can a dependency container resolve this? Is it supposed to do so? Or is it just bad design from the beginning on?

    Read the article

  • hosting simple python scripts in a container to handle concurrency, configuration, caching, etc.

    - by Justin Grant
    My first real-world Python project is to write a simple framework (or re-use/adapt an existing one) which can wrap small python scripts (which are used to gather custom data for a monitoring tool) with a "container" to handle boilerplate tasks like: fetching a script's configuration from a file (and keeping that info up to date if the file changes and handle decryption of sensitive config data) running multiple instances of the same script in different threads instead of spinning up a new process for each one expose an API for caching expensive data and storing persistent state from one script invocation to the next Today, script authors must handle the issues above, which usually means that most script authors don't handle them correctly, causing bugs and performance problems. In addition to avoiding bugs, we want a solution which lowers the bar to create and maintain scripts, especially given that many script authors may not be trained programmers. Below are examples of the API I've been thinking of, and which I'm looking to get your feedback about. A scripter would need to build a single method which takes (as input) the configuration that the script needs to do its job, and either returns a python object or calls a method to stream back data in chunks. Optionally, a scripter could supply methods to handle startup and/or shutdown tasks. HTTP-fetching script example (in pseudocode, omitting the actual data-fetching details to focus on the container's API): def run (config, context, cache) : results = http_library_call (config.url, config.http_method, config.username, config.password, ...) return { html : results.html, status_code : results.status, headers : results.response_headers } def init(config, context, cache) : config.max_threads = 20 # up to 20 URLs at one time (per process) config.max_processes = 3 # launch up to 3 concurrent processes config.keepalive = 1200 # keep process alive for 10 mins without another call config.process_recycle.requests = 1000 # restart the process every 1000 requests (to avoid leaks) config.kill_timeout = 600 # kill the process if any call lasts longer than 10 minutes Database-data fetching script example might look like this (in pseudocode): def run (config, context, cache) : expensive = context.cache["something_expensive"] for record in db_library_call (expensive, context.checkpoint, config.connection_string) : context.log (record, "logDate") # log all properties, optionally specify name of timestamp property last_date = record["logDate"] context.checkpoint = last_date # persistent checkpoint, used next time through def init(config, context, cache) : cache["something_expensive"] = get_expensive_thing() def shutdown(config, context, cache) : expensive = cache["something_expensive"] expensive.release_me() Is this API appropriately "pythonic", or are there things I should do to make this more natural to the Python scripter? (I'm more familiar with building C++/C#/Java APIs so I suspect I'm missing useful Python idioms.) Specific questions: is it natural to pass a "config" object into a method and ask the callee to set various configuration options? Or is there another preferred way to do this? when a callee needs to stream data back to its caller, is a method like context.log() (see above) appropriate, or should I be using yield instead? (yeild seems natural, but I worry it'd be over the head of most scripters) My approach requires scripts to define functions with predefined names (e.g. "run", "init", "shutdown"). Is this a good way to do it? If not, what other mechanism would be more natural? I'm passing the same config, context, cache parameters into every method. Would it be better to use a single "context" parameter instead? Would it be better to use global variables instead? Finally, are there existing libraries you'd recommend to make this kind of simple "script-running container" easier to write?

    Read the article

  • Reinject dependencies of a freshly deserialized object

    - by NathanE
    If a program has literally just deserialized an object (doesn't really matter how, but just say BinaryFormatter was used). What is a good design to use for re-injecting the dependencies of this object? Is there a common pattern for this? I suppose I would need to wrap the Deserialize() method up to act as a factory inside the container. Thanks!

    Read the article

  • How do I bind Different Interfaces using Google Guice?

    - by kunjaan
    Do I need to create a new module with the Interface bound to a different implementation? Chef newChef = Guice.createInjector(Stage.DEVELOPMENT, new Module() { @Override public void configure(Binder binder) { binder.bind(FortuneService.class).to(FortuneServiceImpl.class); } }).getInstance(Chef.class); Chef newChef2 = Guice.createInjector(Stage.DEVELOPMENT, new Module() { @Override public void configure(Binder binder) { binder.bind(FortuneService.class).to(FortuneServiceImpl2.class); } }).getInstance(Chef.class); I cannot touch the Chef Class nor the Interfaces. I am just a client binding to Chef's FortuneService to different Interfaces at runtime.

    Read the article

  • How do I create different Objects using Google Guice?

    - by kunjaan
    I have a Module which binds an Interface to a particular implementation. I use that module to create an object. How do I create a different kind of object with the the interface bound to a different implementation? Do I need to create a new module with the Interface bound to a different implementation?

    Read the article

  • How do I pass dependency to object with Castle Windsor and MS Test?

    - by Nick
    I am trying to use Castle Windsor with MS Test. The test class only seems to use the default constructor. How do I configure Castle to resolve the service in the constructor? Here is the Test Class' constructors: private readonly IWebBrowser _browser; public DepressionSummaryTests() { } public DepressionSummaryTests(IWebBrowser browser) { _browser = browser; } My component in the app config looks like so: <castle> <components> <component id="browser" service="ConversationSummary.IWebBrowser, ConversationSummary" type="ConversationSummary.Browser" /> </components> </castle> Here is my application container: public class ApplicationContainer : WindsorContainer { private static IWindsorContainer container; static ApplicationContainer() { container = new WindsorContainer(new XmlInterpreter(new ConfigResource("castle"))); } private static IWindsorContainer Container { get { return container; } } public static IWebBrowser Browser { get { return (IWebBrowser) Container.Resolve("browser"); } } } MS test requires the default constructor. What am I missing? Thanks!

    Read the article

  • Best loose way to get objects with common base class

    - by Michael Teper
    I struggled to come up with a good title for this question, so suggestions are welcome. Let's say we have an abstract base class ActionBase that looks something like this: public abstract class ActionBase { public abstract string Name { get; } public abstract string Description { get; } // rest of declaration follows } And we have a bunch of different actions defined, like a MoveFileAction, WriteToRegistryAction, etc. These actions get attached to Worker objects: public class Worker { private IList<ActionBase> _actions = new List<ActionBase>(); public IList<ActionBase> Actions { get { return _actions; } } // worker stuff ... } So far, pretty straight-forward. Now, I'd like to have a UI for setting up Workers, assigning Actions, setting properties, and so on. In this UI, I want to present a list of all available actions, along with their properties, and for that I'd want to first gather up all the names and descriptions of available actions (plus the type) into a collection of the following type of item: public class ActionDescriptor { public string Name { get; } public string Description { get; } poblic Type Type { get; } } Certainly, I can use reflection to do this, but is there a better way? Having Name and Description be instance properties of ActionBase (as opposed to statics on derived classes) smells a bit, but there isn't an abstract static in C#. Thank you!

    Read the article

  • autofac's Func<T> to resolve named service

    - by ppiotrowicz
    Given registered services: builder.RegisterType<Foo1>().Named<IFoo>("one").As<IFoo>(); builder.RegisterType<Foo2>().Named<IFoo>("two").As<IFoo>(); builder.RegisterType<Foo3>().Named<IFoo>("three").As<IFoo>(); Can I retrieve named implementations of IFoo interface by injecting something like Func<string, IFoo ? public class SomeClass(Func<string, IFoo> foo) { var f = foo("one"); Debug.Assert(f is Foo1); var g = foo("two"); Debug.Assert(g is Foo2); var h = foo("three"); Debug.Assert(h is Foo3); } I know I can do it with Meta<, but I don't want to use it.

    Read the article

  • When is a Transient-scope object Deactivated in Ninject?

    - by nwahmaet
    When an object in Ninject is bound with InTransientScope(), the object isn't placed into the cache, since it's, er, transient and not scoped to anything. When done with the object, I can call kernel.Release(obj); this passes through to the Cache where it retrieves the cached item and calls Pipeline.Deactivate using the cached entry. But since transient objects aren't cached, this doesn't happen. I haven't been able to figure out where (or who) performs the deactivation for transient objects. Or is the assumption that transient objects are only ever activated, and that if I want a deactivateable object, I need to use some other scope?

    Read the article

  • IOC Container that can target .NET Framework Client Profile?

    - by Rox Wen
    On our current WPF project, we've been performing dependency injection using the Ninject IOC tool. We want to target the .NET Framework Client Profile for a better download/install experience. The problem is that Ninject seems to reference libararies such as System.Web which are NOT in the Client Profile. Can anyone recommend an IOC container that can target the .NET Framework Client Profile (3.5 or 4) ?

    Read the article

  • IoC Dependancy injection into Custom HTTP Module - how? (ASP.NET)

    - by Sosh
    Hi, I have a custom HTTP Module. I would like to inject the logger using my IoC framework, so I can log errors in the module. However, of course I don't get a constructor, so can't inject it into that. What's the best way to go about this? If you need the specific IoC container - I'm currently using Windsor, but may soon move to AutoFac. Thanks

    Read the article

  • Replace Spring.Net IoC with another Container (e.g. Ninject)

    - by Jeffrey Cameron
    Hey all, I'm curious to know if it's possible to replace Spring.Net's built-in IoC container with Ninject. We use Ninject on my team for IoC in our other projects so I would like to continue using that container if possible. Is this possible? Has anyone written a Ninject-Spring.Net Adapter?? Edit I like many parts of the Spring.Net package (the data access, transactions, etc.) but I don't really like the dependency injection container. I would like to replace that with Ninject Thanks

    Read the article

  • IOC are at the class level, but what about database conflicts?

    - by mrblah
    With IOC I understand you can substitue implementations out by merely editing a configuration file etc. BUT, what happens when the classes are married to particular database tables and sprocs, you can't just swap out an implementation since the classes/entities are tied to particular tables and stored procedures. Am I right here?

    Read the article

  • Is it possible to use Dependency Injection/IoC on an ASP.NET MVC FilterAttribute ?

    - by Pure.Krome
    Hi folks, I've got a simple custom FilterAttribute which I use decorate various ActionMethods. eg. [AcceptVerbs(HttpVerbs.Get)] [MyCustomFilter] public ActionResult Bar(...) { ... } Now, I wish to add some logging to this CustomFilter Action .. so being a good boy, I'm using DI/IoC ... and as such wish to use this pattern for my custom FilterAttribute. So if i have the following... ILoggingService and wish to add this my custom FilterAttribute .. i'm not sure how. Like, it's easy for me to do the following... public class MyCustomFilterAttribute : FilterAttribute { public MyCustomFilterAttribute(ILoggingService loggingService) { ... } } But the compiler errors saying the attribute which decorates my ActionMethod (listed above...) requires 1 arg .. so i'm just not sure what to do :(

    Read the article

  • Passing Func<T> to controller constructure when using Unity IoC with MVC, advantages?

    - by user1361315
    I was looking at a sample of how to setup Unity IoC with MVC, and noticed someone who recommended the approach of having the parameters of Func. I believe the advantage is this is kind of like lazy loading the service, if it never gets called it will never get executed and not consume any resources. private readonly Func<IUserService> _userService; public CourseController(Func<IUserService> userService) { this._userService = userService; } Versus a parameter without a Func: private readonly IUserService _userService; public CourseController(IUserService userService) { this._userService = userService; } Can someone explain to me the differences, is it really more effecient?

    Read the article

  • How to handle "circular dependency" in dependency injection

    - by Roel
    The title says "Circular Dependency", but it is not the correct wording, because to me the design seems solid. However, consider the following scenario, where the blue parts are given from external partner, and orange is my own implementation. Also assume there is more then one ConcreteMain, but I want to use a specific one. (In reality, each class has some more dependencies, but I tried to simplify it here) I would like to instanciate all of this with Depency Injection (Unity), but I obviously get a StackOverflowException on the following code, because Runner tries to instantiate ConcreteMain, and ConcreteMain needs a Runner. IUnityContainer ioc = new UnityContainer(); ioc.RegisterType<IMain, ConcreteMain>() .RegisterType<IMainCallback, Runner>(); var runner = ioc.Resolve<Runner>(); How can I avouid this? Is there any way to structure this so that I can use it with DI? The scenario I'm doing now is setting everything up manually, but that puts a hard dependency on ConcreteMain in the class which instantiates it. This is what i'm trying to avoid (with Unity registrations in configuration). All source code below (very simplified example!); public class Program { public static void Main(string[] args) { IUnityContainer ioc = new UnityContainer(); ioc.RegisterType<IMain, ConcreteMain>() .RegisterType<IMainCallback, Runner>(); var runner = ioc.Resolve<Runner>(); Console.WriteLine("invoking runner..."); runner.DoSomethingAwesome(); Console.ReadLine(); } } public class Runner : IMainCallback { private readonly IMain mainServer; public Runner(IMain mainServer) { this.mainServer = mainServer; } public void DoSomethingAwesome() { Console.WriteLine("trying to do something awesome"); mainServer.DoSomething(); } public void SomethingIsDone(object something) { Console.WriteLine("hey look, something is finally done."); } } public interface IMain { void DoSomething(); } public interface IMainCallback { void SomethingIsDone(object something); } public abstract class AbstractMain : IMain { protected readonly IMainCallback callback; protected AbstractMain(IMainCallback callback) { this.callback = callback; } public abstract void DoSomething(); } public class ConcreteMain : AbstractMain { public ConcreteMain(IMainCallback callback) : base(callback){} public override void DoSomething() { Console.WriteLine("starting to do something..."); var task = Task.Factory.StartNew(() =>{ Thread.Sleep(5000);/*very long running task*/ }); task.ContinueWith(t => callback.SomethingIsDone(true)); } }

    Read the article

< Previous Page | 6 7 8 9 10 11 12 13 14 15 16 17  | Next Page >