Coder Social home page Coder Social logo

ninject.extensions.wcf's Introduction

Ninject

Build status codecov NuGet Version NuGet Downloads

Ninject is a lightning-fast, ultra-lightweight dependency injector for .NET applications. It helps you split your application into a collection of loosely-coupled, highly-cohesive pieces, and then glue them back together in a flexible manner. By using Ninject to support your software's architecture, your code will become easier to write, reuse, test, and modify.

Write your code so it's flexible...

public class Samurai {
    public IWeapon Weapon { get; private set; }
    public Samurai(IWeapon weapon) 
    {
        this.Weapon = weapon;
    }
}

...and let Ninject glue it together for you.

public class WarriorModule : NinjectModule
{
    public override void Load() 
    {
        this.Bind<IWeapon>().To<Sword>();
    }
}

Features:

  1. Focused. Too many existing dependency injection projects sacrifice usability for features that aren't often necessary. Each time a feature is added to Ninject, its benefit is weighed against the complexity it adds to everyday use. Our goal is to keep the barrier to entry - the baseline level of knowledge required to use Ninject - as low as possible. Ninject has many advanced features, but understanding them is not required to use the basic features.

  2. Sleek. Framework bloat is a major concern for some projects, and as such, all of Ninject's core functionality is in a single assembly with no dependencies outside the .NET base class library. This single assembly's footprint is approximately 85KB when compiled for release.

  3. Fast. Instead of relying on reflection for invocation, Ninject takes advantage of lightweight code generation in the CLR. This can result in a dramatic (8-50x) improvement in performance in many situations.

  4. Precise. Ninject helps developers get things right the first time around. Rather than relying on XML mapping files and string identifiers to wire up components, Ninject provides a robust domain-specific language. This means that Ninject takes advantage of the capabilities of the language (like type-safety) and the IDE (like IntelliSense and code completion).

  5. Agile. Ninject is designed around a component-based architecture, with customization and evolution in mind. Many facets of the system can be augmented or modified to fit the requirements of each project.

  6. Stealthy. Ninject will not invade your code. You can easily isolate the dependency on Ninject to a single assembly in your project.

  7. Powerful. Ninject includes many advanced features. For example, Ninject is the first dependency injector to support contextual binding, in which a different concrete implementation of a service may be injected depending on the context in which it is requested.

Everything else is in Extensions

Yes, sounds slim and focused, but where is the support for all the features that the competitors have?

Generally, they are maintained as specific focused extensions with owners who keep them in sync and pull in new ideas and fixes fast. These are summarized on the extensions section of the project website. Most are hosted alongside the core project right here.

License

Ninject is intended to be used in both open-source and commercial environments. To allow its use in as many situations as possible, Ninject is dual-licensed. You may choose to use Ninject under either the Apache License, Version 2.0, or the Microsoft Public License (Ms-PL). These licenses are essentially identical, but you are encouraged to evaluate both to determine which best fits your intended use.

Refer to LICENSE.txt for detailed information.

Changes history

Resources

ninject.extensions.wcf's People

Contributors

cbertolasio avatar chafey avatar danielmarbach avatar dependabot[bot] avatar drieseng avatar iappert avatar idavis avatar mortenn avatar remogloor avatar scott-xu avatar stabbylambda avatar testfirstcoder avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

ninject.extensions.wcf's Issues

Need help getting started

Hi,
I am building WCF REST Web Services with .NET 4.0 and would like to use Ninject so I figured I would take a look at this extension. Unfortunately I am having a few issues:

  1. There isn't any documentation on how to get started. Since there was no documentation, I tried to build an example...
  2. But the WcfTimeService does not build out of the box on VS2010. When I open the project, it has a yellow warning sign on the files Global.asax and Web.Config. It also references assemblies which are not included in the source. Since I could not build the example, I figured I would try to build the whole project from source...
  3. But the build system requires NAnt and i wasn't able to get NAnt to work (throws a security exception of some type).

Overall it looks like this project has some useful code that many people would benefit from, but it probably isn't being used very much because it is too hard to get started. I would be willing to help close this gap (write up documentation, create a self contained sample project, create a package with all dependencies, etc) if someone can help me get a build going (I can't really contribute if I can't get it working). I am sure I could get things working by downloading the needed dependencies and tweaking the project files, but figured I would try to give something back here and make it easier for the next guy...

Chris

A better sample is needed

Hi,

I downloaded the zip file and had a look around, and I do not understand how to apply this to a WCF service library.
None of my WCF services are hosted in a website or windows application, I merely publish the service library to a web server, letting visual studio create the needed .svc files automatically.

So, I would greatly appreciate it if a sample could be built that uses a WCF service library as a base, rather than a web site.

-- Regards, Morten

Support Ninject BehaviorExtensionElement to inject WCF behaviors

namespace Ninject.Extensions.Wcf
{
    using System;
    using System.ServiceModel.Configuration;
    using System.ServiceModel.Description;

    using Ninject;

    public abstract class NinjectBehaviorExtensionElementBase : BehaviorExtensionElement
    {
        private static IKernel kernel;

        public static void SetKernel(IKernel kernel)
        {
            NinjectBehaviorExtensionElementBase.kernel = kernel;
        }

        public class NinjectBehaviorExtensionElement<T> : NinjectBehaviorExtensionElementBase where T : class
        {
            public override Type BehaviorType
            {
                get { return typeof(T); }
            }

            protected override object CreateBehavior()
            {
                return kernel.Get<T>();
            }
        }
    }
}

config file

<system.serviceModel>
...
  <extensions>
    <behaviorExtensions>
      <add name="yourBehaviorName" type="Ninject.Extensions.Wcf.NinjectBehaviorExtensionElementBase+NinjectBehaviorExtensionElement`1[[YourAssembly.YourBehavior, YourAssembly]], Ninject.Extensions.Wcf" />
    </behaviorExtensions>
  </extensions>
...
</system.serviceModel>

When application start, set the kernel:

NinjectBehaviorExtensionElementBase.SetKernel(yourKernel);

Nuget Package out of date

Hey, it looks like the nuget package for this extension is quite out of date in relation to the examples, could you please re-release the package?

Examples are really correct ?

Hi,

looking at the example 'TimeService.svc.cs' one can see that this service is always instantiated with an instance of SystemClock.cs (new SystemClock()). As the factory can only handle this non-arg constructor i don't see a chance how to change the implmententation of ISystemClock.

From my point of view this has nothing to do with DI or am i missing something ?

Greets
syracus

Example.WcfRestService not working with the current ninject version (Ninject 3.0.1.10)

I'm trying to upgrade from ninject 2.2.0 to the latest version Ninject 3.0.1.10 and trying to figure out how to use the latest version of Ninject with WCF REST. However, when I try to run the Example WcfRestService, I'm getting a 500 error:
Error activating IntPtr
No matching bindings are available, and the type is not self-bindable.
Activation path:
3) Injection of dependency IntPtr into parameter method of constructor of type Func{IKernel}
2) Injection of dependency Func{IKernel} into parameter lazyKernel of constructor of type HttpApplicationInitializationHttpModule

  1. Request for IHttpModule

Suggestions:

  1. Ensure that you have defined a binding for IntPtr.
  2. If the binding was defined in a module, ensure that the module has been loaded into the kernel.
  3. Ensure you have not accidentally created more than one kernel.
  4. If you are using constructor arguments, ensure that the parameter name matches the constructors parameter name.
  5. If you are using automatic module loading, ensure the search path and filters are correct.

This error is similar to what I get when I attempted to upgraded my existing code to use Ninject 3.0.1.10

Parse error

Hi , i manage to build and run the files but the following error occurs.

Inheritance security rules violated while overriding member: 'Ninject.Web.Common.NinjectHttpApplication.get_Kernel()'. Security accessibility of the overriding method must match the security accessibility of the method being overriden.

Would you know the cause and resolution for this? thank you :)

Nuget install fails on .Net 3.5

Attempting to install Ninject.Extensions.Wcf 3.2.2 nuget package on a .Net 3.5 WCF service on windows 8.1 It fails with the following error in the package manager console:

Failed to add reference to 'System.ServiceModel.Activation'. Please make sure that it is in the Global > Assembly Cache.

Tried using version 3.0.0.5 and then come accross this bug: ninject/Ninject.Web.Common#6

The full package manager output is below...

Attempting to gather dependencies information for package 'Ninject.Extensions.Wcf.3.2.2' with respect to project 'InstrumentServer\Optimal.SynTQ.InstrumentServer.Kaiser.Services', targeting '.NETFramework,Version=v3.5'
Attempting to resolve dependencies for package 'Ninject.Extensions.Wcf.3.2.2' with DependencyBehavior 'Lowest'
Resolving actions to install package 'Ninject.Extensions.Wcf.3.2.2'
Resolved actions to install package 'Ninject.Extensions.Wcf.3.2.2'
Adding package 'Ninject.Extensions.Wcf.3.2.2' to folder 'C:\Projects\SynTQ\dev\packages'
Added package 'Ninject.Extensions.Wcf.3.2.2' to folder 'C:\Projects\SynTQ\dev\packages'
Install failed. Rolling back...
Package 'Ninject.Extensions.Wcf 3.2.2' does not exist in project 'Optimal.SynTQ.InstrumentServer.Kaiser.Services'
Removing package 'Ninject.Extensions.Wcf 3.2.2' from folder 'C:\Projects\SynTQ\dev\packages'
Removed package 'Ninject.Extensions.Wcf 3.2.2' from folder 'C:\Projects\SynTQ\dev\packages'
Failed to add reference to 'System.ServiceModel.Activation'. Please make sure that it is in the Global Assembly Cache.
========== Finished ==========

Need bump version

Currently the latest nuget package is 3.2.0-unstable-004 which is lower than 3.2.0.

image

Should not release scope at request end when InstanceContextMode is Single, by default

Given:

  • using Factory extension MyService(Lazy<IDependency1> d1)
  • dependencies are in request scope Bind<IDependency1>().To<Dependency1>().InRequestScope()
  • Dependency1 has un-managed resources and implemented IDisposable interface
  • MyService InstanceContextMode is Single

When:
Call the service at the second time

Then:
The un-managed resources should still be avaliable

NinjectFileLessServiceHostFactory sample for WcfLibrary is not working

Even though I've downloaded all pre packages from nuget, and solution get compiled successfully but NinjectFileLessServiceHostFactory never get called upon running the project and I'll get this error message: (service type provided could not be loaded as a service because it does not have a default (parameter-less) constructor)

System.InvalidOperationException: The service type provided could not be loaded as a service because it does not have a default (parameter-less) constructor. To fix the problem, add a default constructor to the type, or pass an instance of the type to the host.
   at System.ServiceModel.Dispatcher.InstanceBehavior..ctor(DispatchRuntime dispatch, ImmutableDispatchRuntime immutableRuntime)
   at System.ServiceModel.Dispatcher.ImmutableDispatchRuntime..ctor(DispatchRuntime dispatch)
   at System.ServiceModel.Dispatcher.DispatchRuntime.GetRuntimeCore()
   at System.ServiceModel.Dispatcher.ChannelDispatcher.OnOpened()
   at System.ServiceModel.Channels.CommunicationObject.Open(TimeSpan timeout)
   at System.ServiceModel.ServiceHostBase.OnOpen(TimeSpan timeout)
   at System.ServiceModel.Channels.CommunicationObject.Open(TimeSpan timeout)
   at Microsoft.Tools.SvcHost.ServiceHostHelper.OpenService(ServiceInfo info)

Cannot build using build-release.cmd

I'm unable to build because of a signing issue. The message goes like this:

  [csc] Compiling 8 files to 'C:\workspace\ninject.extensions.wcf\bin\net-3.5\release\Ninject.Extensions.Wcf.dll'.
  [csc] c:\workspace\ninject.extensions.wcf\source\Ninject.Extensions.Wcf\NinjectServiceBehavior.cs(26,18): error CS1591: Warning as Error: Missing XML comment for publicly visible type or member 'Ninject.Extensions.Wcf.NinjectServiceBehavior'
  [csc] error CS1606: Assembly signing failed; output may not be signed -- The system cannot find the file specified.

  BUILD FAILED

New nuget package?

Hello :)

There has not been any activity on nuget for this package in about a year; are there plans to release a new package? Thanks!

Best regards,
Cornelius

Incorrect frameworkAssembly in nuget package for Ninject.Extensions.Wcf

The nuget package for Ninject.Extensions.Wcf lists a dependency on the System.ServiceModel.Activation assembly.

However, this dependency only applies to the .NET 4.0 and 4.5 versions of this extension.
The nuspec actually enforces this dependency for all included .NET Framework versions.
This means that the package is not usable for .NET Framework 3.5 as that version does not even include the System.ServiceModel.Activation assembly.

Dispose the dependencies too early

For case below, if we release the repository at BeforeSendReply, the let j = this.repository.GetItems() will throw object disposed exception.

[WebGet(UriTemplate = "")]
public IEnumerable<SampleItem> GetItems()
{
    return from i in this.repository.GetItems()
           // use this.repository again to check it is not disposed.
           let j = this.repository.GetItems()
           select i;
}

App_Start folder not created when installing Ninject.Extensions.Wcf from NuGet

After creating a new Wcf Service Application using Visual Studio 2013 and installing Ninject.Extensions.Wcf using Nuget there is no App_Start folder created nor a NinjectWebCommon class.

Also, after creating a new Web Site using the Wcf Service template and installing Ninject.Extensions.Wcf using Nuget there is still no App_Start folder created nor a NinjectWebCommon class.

Finally, after creating a new Web Site using the Wcf Service template hosted in IIS and installing Ninject.Extensions.Wcf using Nuget there is still no App_Start folder created nor a NinjectWebCommon class.

Update example to replace the obsolete NinjectWebServiceHostFactory and use NinjectServiceHostFactory

I am trying to figure out how to expose my service as a REST service and not use the now obsolete NinjectWebServiceHostFactory.

In the example Ninject.Extensions.Wcf/src/Examples/WcfRestService/Global.asax.cs it uses the obsolete NinjectWebServiceHostFactory.

RouteTable.Routes.Add(new ServiceRoute("Service1", new NinjectWebServiceHostFactory(), typeof(Service1)));

So when I change it to the code below I can no longer send application/json requests to it. It complains and says it is expecting xml.

RouteTable.Routes.Add(new ServiceRoute("Service1", new NinjectServiceHostFactory(), typeof(Service1)));

How do I use the NinjectServiceHostFactory and create my route as a REST route.
Should NinjectWebServiceHostFactory really be obsolete?

WCF-Discovery is not working

WCF-Discovery is not working if Ninject.Extensions.Wcf.NinjectServiceHostFactory is used.

It is a bug in Ninject.Extensions.Wcf.NinjectServiceBehavior class. To fix it just need to add in ApplyDispatchBehavior method a check if endpointDispatcher.DispatchRuntime.InstanceProvider is null because WS-Discovery creates new endpoints with defined InstanceProvider which should not be overwritten.

public void ApplyDispatchBehavior(ServiceDescription serviceDescription, ServiceHostBase serviceHostBase)
{
foreach (EndpointDispatcher endpointDispatcher in serviceHostBase.ChannelDispatchers.OfType().SelectMany(channelDispatcher => (IEnumerable) channelDispatcher.Endpoints))
{
if (endpointDispatcher.DispatchRuntime.InstanceProvider == null)
{
endpointDispatcher.DispatchRuntime.InstanceProvider = _instanceProviderFactory(serviceDescription.ServiceType);
endpointDispatcher.DispatchRuntime.MessageInspectors.Add(_requestScopeCleanUp);
}
}
}

Read request message body while binding dependency using ninject.extensions.wcf

Also asked here http://stackoverflow.com/questions/23686009/

I am using Ninject.Extensions.Wcf in a WCF service, and also have the Ninject.Web.Common package in my project.

In the NinjectWebCommon class this is how I bind my dependency

kernel.Bind<ISomething>().To<ConcreteSomething>();

straightforward binding, and everything works..

Now, I want to do the resolution based on some members in the message request body, so I create a provider

kernel.Bind<ISomething>().ToProvider<SomethingProvider>();

And SomethingProvider tries to read the request message like this

public class SomethingProvider : Provider<ISomething>
{
    protected override ISomething CreateInstance(IContext context)
    {
        var message = OperationContext.Current.RequestContext.RequestMessage;
        //message.State is Read here, so CreateBufferedCopy throws an InvalidOperationException.

        var buffer = message.CreateBufferedCopy(int.MaxValue);
        message = buffer.CreateMessage();
        var messageCopy = buffer.CreateMessage();
        var body = messageCopy.GetBody<string>();

        //Parse body, check some members and return one of the "Somethings"
        return new AnotherConcreteSomething();
    }
}

This throws an invalid operation exception. The RequestMessage in the operationcontext is already in read state, so I cant read it again.

I read that RequestMessage.ToString() is not always reliable since it truncates the body. And, I will have to get the body from the whole SOAP message.

Is there any other way I can do this? Is this approach even correct? I cant get this information in the header, it is in the body :(.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.